Execution speed too slowly

The execution speed too slowly, especially below method :


asProject.getResourceAssignments().add(asTask, asResource);

It tasks about 1-2 second for execute this method.

why?

Hi zhencheng,

Thank you for writing to Aspose Support team.

We have tested this issue with the following sample code but were not able to observe the behavior you have mentioned. Can you please try the following with the latest version of the API and share your feedback with us? Also, it seems that the issue may be specific to your sample file. Could you also please share that with us for our further investigation? We’ll look into it and assist you further.

Sample Code:

Project project = new Project(“Blank2010.mpp”);

Task t1 = project.getRootTask().getChildren().add(“T1”);
Resource r1 = project.getResources().add();

System.out.println(new Date());

ResourceAssignment ra = project.getResourceAssignments().add(t1, r1);

System.out.println(new Date());

project.save(“resaved.mpp”, SaveFileFormat.MPP);

I'm using aspose-tasks-9.3.0-jdk18.jar for it, the test code is below:


package com.hp.aspose;


import java.util.Calendar;

import com.aspose.tasks.NullableBool;
import com.aspose.tasks.Project;
import com.aspose.tasks.Resource;
import com.aspose.tasks.SaveFileFormat;
import com.aspose.tasks.Task;
import com.aspose.tasks.Tsk;

public class AsPoseTest {
public static void main(String[] args) {
Project project = new Project("Project_blank.mpp");

for (int i = 0; i < 1000; i++) {
Resource resource = project.getResources().add("aaa" + i );
Task asTask = project.getRootTask().getChildren().add("Root task" + i);
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
asTask.set(Tsk.START, cal1.getTime());
asTask.set(Tsk.FINISH, cal2.getTime());
asTask.set(Tsk.UID, i);
asTask.set(Tsk.WORK, project.getDuration(8));
asTask.set(Tsk.IS_MILESTONE, new NullableBool(false));
asTask.set(Tsk.NAME, "test" + i);

Integer type = 2;
if (type != null) {
asTask.set(Tsk.CONSTRAINT_TYPE, type.intValue());
}

asTask.set(Tsk.CONSTRAINT_DATE,cal1.getTime());
asTask.set(Tsk.PRIORITY, 500);
asTask.set(Tsk.IS_CRITICAL, new NullableBool(true));
asTask.set(Tsk.TOTAL_SLACK, 3);
// if (task.getOutlineLevel() != null) {
// asTask.set(Tsk.OUTLINE_LEVEL, task.getOutlineLevel().intValue());
// }
asTask.set(Tsk.ACTUAL_START, cal1.getTime());
asTask.set(Tsk.ACTUAL_FINISH, cal2.getTime());

asTask.set(Tsk.ACTUAL_DURATION, project.getDuration(24));
asTask.set(Tsk.PERCENT_COMPLETE,90);
asTask.set(Tsk.REMAINING_WORK, project.getDuration(16));
project.getResourceAssignments().add(asTask, resource);
System.out.println(i);
}
// Save the Project
project.save("task.mpp", SaveFileFormat.MPP);
System.out.println("ok");
}
}

Hi Zhencheng,

I have modified the above sample code to display time interval in milliseconds for execution of each project.getResourceAssignments().add(asTask, resource) as shown below:

final long startTime = System.currentTimeMillis();
project.getResourceAssignments().add(asTask, resource);
final long endTime = System.currentTimeMillis();
System.out.println("Total execution time: " + (endTime - startTime));

The output file is attached here which shows an average time of about 15 ms to execute this statement in each iteration. My test machine specifications are as follows:

Processor: 2.53 GHz

RAM: 4 GB

OS: Windows 10 (64 bit)

I am afraid that issue is not re-produced here and you may test this code on some other machines for better comparison. Please feel free if you have any other query related to Aspose.Tasks.

Is it a difference between trial version and official version on performance?

Hi Zhencheng,

In trial versions, all dates are set to 2000 and the performance should be more improved as compared to the licensed version where all dates are properly calculated. Please try the license version as you will be getting wrong dates information while working with trial version without a license.

Hi,


The delay occurs when we work on generating a very large MPP file (~ 10.000 tasks).

Does the execution time of this operation remain constant when the size of the MPP file increases?

Hi Zhencheng,


Thank you for writing to us again.

Above sample code is executed 10000 times and it is observed that getResourceAssignments() function takes minimum 3 milli seconds (ms) and maximum 650 ms. For all the 10000 loops its average time is calculated as 74.6 ms.

We have also calculated the average time of complete for loop which takes minimum time 17 ms and maximum 4 seconds. Average of all the 10000 loops is 1.43 seconds.

Execution time of operation increases while MPP size increases, however project.getResourceAssignments().add(asTask, resource); does not take that much time as it was mentioned in the first post.

Please feel free to write us back if you have any other query in this regard.

Hi Kashif,


With an average of 1.43 second per loop (i.e. per task), filling in a 10k tasks mpp file will take about 4 hours, is that correct?

Is that considered an acceptable level of performance?

As the duration to process one task degrades with the size of the mpp file, this means that generating a 20k tasks mpp file will likely take more than a day.

I do agree that such large mpp files are hardly manageable, but they do occur in enterprise environments. I will do no comment on whether that’s a proper way to manage a project, I’m just stating a fact :slight_smile:

Is there any good practice you could share that would make it possible to generate such large mpp files in a reasonable amount of time?

Kind Regards,
Etienne.

Hi,

I ran more benchmarks with some slightly different code:

Project project = new Project(“c:\temp\project_blank.mpp”);

List resources = new ArrayList(RESOURCES_COUNT);

for (int i = 0; i < 40; i++) {

Resource resource = project.getResources().add(“aaa” + i);

resources.add(resource);

}

for (int i = 0; i < TASKS_COUNT; i++) {

Task asTask = project.getRootTask().getChildren().add("Task " + i);

Date d1 = Calendar.getInstance().getTime();

Calendar c2 = Calendar.getInstance();

c2.add(Calendar.DAY_OF_MONTH, 5);

Date d2 = c2.getTime();

asTask.set(Tsk.START, d1);

asTask.set(Tsk.FINISH, d2);

asTask.set(Tsk.UID, i);

asTask.set(Tsk.WORK, project.getDuration(8));

asTask.set(Tsk.IS_MILESTONE, new NullableBool(false));

asTask.set(Tsk.PRIORITY, 500);

asTask.set(Tsk.ACTUAL_START, d1);

asTask.set(Tsk.ACTUAL_FINISH, d2);

asTask.set(Tsk.ACTUAL_DURATION, project.getDuration(24));

asTask.set(Tsk.PERCENT_COMPLETE,90);

asTask.set(Tsk.REMAINING_WORK, project.getDuration(16));

Resource resource = resources.get(i % RESOURCES_COUNT);

project.getResourceAssignments().add(asTask, resource);

}

// Save the Project

project.save(“Project_” + RESOURCES_COUNT + “_” + TASKS_COUNT + “.mpp”, SaveFileFormat.MPP);

The findings are that Aspose Tasks Java don’t scale well at all:

50 tasks: 18 s
100 tasks: 38 s
200 tasks: 75 s
400 tasks: 222 s
600 tasks: 453 s ( ~ 17 s to write the mpp file)
800 tasks: 900 s (~ 30 s to write the mpp file).

What’s surprising is that one loop did took almost 2 seconds when reaching 800 tasks created, (~300 ms at the beginning when no task is created) which makes it hard to believe that this could scale up to 10k tasks and only take 4 seconds for a loop to complete…

My laptop config is a QuadCore (i7-2860) with 20GB RAM and SSD.

I would have gladly investigated further with a perf profiler, but since Aspose Tasks java code is obfuscated, that makes it really hard for me to dig further than the shallow observation that creating a new resource assignment is slow and doesn’t scale well…

Are you sure that the licensed lib has the same performance as the trial lib? I’m using the trial version for now. That should have changed soon, but this performance profile means that we might have to give up using Aspose Tasks for our project, which is unfortunate.

Thanks,

Etienne.

Hi Kashif,

kashif.iqbal:
[...]Above sample code is executed 10000 times and it is observed that getResourceAssignments() function takes minimum 3 milli seconds (ms) and maximum 650 ms. [...]

The performance problem is not with getResourceAssignments(), it's when calling "add(...)" on the ResourceAssignmentCollection returned by getResourceAssignments().

I tried to find other methods for adding assignments, but I couldn't succeed.

The programmer's guide mentions 2 different ways of creating resources assignments, but there's no mention of what's the other way other than " either using the default constructor or by passing a task and resource"
http://www.aspose.com/docs/display/tasksjava/Creating+Resource+Assignments

The getAssignments() from objects Task and Resource are read-only collections, and we shouldn't instantiate new ResourceAssignment() objects ourselves as the constructor got package-level visibility.

If you know how to create a new ResourceAssignment using "the default constructor", please advise!

Thanks,
Etienne.

Hi Etienne,


Thank you for sharing your feedback.

This issue needs detailed analysis and is logged under Id: TASKS-34586 for further investigation by the product team. You will be automatically notified once any update is received in this regard.

In the latest API, you cannot create new resource assignment using the default constructor. We will update the article soon.

Hi,


In case anyone met the same issue, switching project calculation mode to “Manual” before creating the tasks & assignments really improves performance.
Generating very large work plans (more than 5000 tasks) is still impractical, but this really raises the bar of what’s possible to generate within a few minutes.

Thanks to Iqbal for the trick!

Hi Etienne,


Thank you for the feedback.