dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.21k stars 191 forks source link

Task history takes too long to load on remote server for small number of logs #838

Closed priyank89patel closed 4 years ago

priyank89patel commented 4 years ago

TaskEventLog takes really long time to load logs for a particular task even for small number of logs.

I am using TaskEventLog constructor to connect to a remote server to read logs/history of a task. The code takes really long time to finish even for a small number of logs (30-60 entries). I am not getting any run time exceptions so I think that the creation of TaskEvent object is taking long. Please find below the code and other details.

Any help/suggestions to resolve this issue is greatly appreciated.

TaskEventLog log = new TaskEventLog(@"\Test Task",
                // Specify the event id(s) you want to enumerate
                new int[] {
                    200 /* ActionStart */,
                    201 /* ActionSuccess */ ,
                    202 /* ActionFailure */
                },
 // Specify the start date of the events to enumerate. Here, we look at the last week.
 DateTime.Now.AddDays(-7), "Server", "Domain", "Username", "Password");

// Tell the enumerator to expose events 'newest first'
log.EnumerateInReverse = false;

//The below code takes long time to finish (more than 5 minutes for 50 odd logs)
var history = log.Select(ev => new History
                {
                    Level = ev.Level,
                    Created = ev.TimeCreated,
                    EventId = ev.EventId,
                    TaskCategory = ev.TaskCategory,
                    OperationalCode = ev.OpCode,
                    CorrelationId = ev.ActivityId
                })
                .ToList();

//Custom class for displaying History on the UI
public class History
    {
        public string Level { get; set; }
        public DateTime? Created { get; set; }
        public int EventId { get; set; }
        public string TaskCategory { get; set; }
        public string OperationalCode { get; set; }
        public Guid? CorrelationId { get; set; }
    }
dahall commented 4 years ago

My experience is that the local event log is not fast (even in the Windows Event Log app) and that remote event logs are painfully slow. I'll do a little performance monitoring while running the unit tests for that class and see if any optimization jumps out at me.

dahall commented 4 years ago

As a benchmark, would you mind trying to connect to the remote machine via Window Event Log Viewer and let me know if it appears to be faster?

priyank89patel commented 4 years ago

As a benchmark, would you mind trying to connect to the remote machine via Window Event Log Viewer and let me know if it appears to be faster?

I will definitely try that suggestion and let you know.

priyank89patel commented 4 years ago

My experience is that the local event log is not fast (even in the Windows Event Log app) and that remote event logs are painfully slow. I'll do a little performance monitoring while running the unit tests for that class and see if any optimization jumps out at me.

Fetching local logs without passing server connection details to the TaskEventLog constructor is much faster than the remote version.

dahall commented 4 years ago

So I pulled this code out and looked for optimizations in a few different ways with only very nominal (<2% gains) results. Sorry, but I'm afraid this is a Microsoft library problem that I cannot work-around or fix.

priyank89patel commented 4 years ago

So I pulled this code out and looked for optimizations in a few different ways with only very nominal (<2% gains) results. Sorry, but I'm afraid this is a Microsoft library problem that I cannot work-around or fix.

Yes, this surely is a Microsoft issue. However, I noticed that the same code performs better (much quicker) when deployed to some of our environments (DEV & TEST) so I think it is really slower on my work computer (may be some restrictions/security things I haven't figured out yet).

I appreciate your time and all the help with this. Thank you!

Fenix-Z commented 4 years ago

Yes, this surely is a Microsoft issue. However, I noticed that the same code performs better (much quicker) when deployed to some of our environments (DEV & TEST) so I think it is really slower on my work computer (may be some restrictions/security things I haven't figured out yet).

I appreciate your time and all the help with this. Thank you!

I have the same issue. Please could you tell me whether you have found the reason of your performance problems?

priyank89patel commented 4 years ago

Yes, this surely is a Microsoft issue. However, I noticed that the same code performs better (much quicker) when deployed to some of our environments (DEV & TEST) so I think it is really slower on my work computer (may be some restrictions/security things I haven't figured out yet). I appreciate your time and all the help with this. Thank you!

I have the same issue. Please could you tell me whether you have found the reason of your performance problems?

Unfortunately I could not find any solution to fix the performance issue, however, there was a significant performance improvement after the application was deployed to server. I was facing this issue on my workstation.