1

I need your help.

I made a console application with C# net.4.5 ans AWSSDK V3.3 , to configure my intance at startup.

My probleme is, at the first start of my instance (windows server 2008r2) the application starting EXTREMELY slowly and running EXTREMELY slowly.

Indeed, i use "Task scheduler" to start the app at boot time.

When i reboot the instance or restart (or even fresh start) the app, everithing work fine.

  • When i start the app manually: the task (all the things that the app have todo) is completed in less than 40 secondes.
  • When i start the app at boot time with Task scheduler: the task taking over than 5 minutes! to complete. (What a cold start!)

  • I have delayed the start of my app (with a /timout .bat) (90secondes) > app still extremly slow...

  • I have delayed the start of my app (with a /timout .bat) (300 secondes), to be absolutly sure that all the .net frameworks is fully loaded > everithing work fine!

So, now i have to run hundred of spot-instances with this startup app.... if i loose 5 minutes at startup on each instance, i'll loose a looot of money!

What do you think about my case? do you think i'am right about the .net framworks pre-loading? is it possible to make it load faster?

i'am aware of ngen.exe, i tried it on the .exe and dlls. but the problem still the same. i think that the problem is more global, not specific to my app.

For your information:

in my app From the SDK i use:

  • EC2InstanceMetadata
  • AmazonS3Client
  • GetObjectRequest
  • GetObjectResponse

Credentials are stored ine app.config

All this class are called one time. (no retry loop if failling). I mean, if there is no internet the app crash or return Exception. The app is made in VS 2015, and the AWSSDK dlls are in the root folder of the .exe

Thanks you, for your help!

---------------------------- edit ------------------

I did a simple test with a simple clean console (Visual studio 2015 template) code (writing 100 txt file on C:). I ran the programme at startup with Task scheduler, and it toke 5 minutes to accomplish this huge task.... so it seem that the probleme is not my code.

edit: I also tried the simple test app with ".net framework 3.5 client". same thing... app hang for 4 minutes then do the job. (6 minutes in total).

@MaLiN2223 May be making a service rather than a console app is a solution... i should try. What my startup app do:

  • Donwload files on amazon S3

  • get instance infos from aws-sdk

  • Start Or Stop services

  • Change value in .ini

  • Mount network drive

  • reading xml value

  • start applications

for your information, the test code:

using System;
using System.IO;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 100; i++)
            {
                Console.Write("Writting file nb: " + i.ToString());
                File.Create(@"C:\test_" + i.ToString() + ".txt");

            }
            log();
            Console.ReadKey();
        }
        static void log()
        {
            using (StreamWriter writer = new StreamWriter("C:\\test_log.txt"))
            {
                var uptime02 = new PerformanceCounter("System", "System Up Time");
                uptime02.NextValue();       //Call this an extra time before reading its value
                var timeTowrite = TimeSpan.FromSeconds(uptime02.NextValue());
                writer.WriteLine(timeTowrite);
            }
        }
    }
}
Romeh
  • 29
  • 8
  • It might be **extremely** hard to debug this for us without any code. Did you applied some polices to this windows server? Because : [This might be the case](https://support.microsoft.com/en-us/help/969972/you-encounter-a-slow-application-startup-or-a-slow-logon-on-a-computer-that-is-running-windows-server-2008-or-windows-vista-after-you-apply-software-restriction-policies). I also recomend for you to read [THIS](https://blogs.technet.microsoft.com/markrussinovich/2010/12/06/the-case-of-the-slow-project-file-opens/), it **might** help to identify the problem. – MaLiN2223 Feb 01 '17 at 17:23
  • (Second comment because I am out of characters back there) You might also look for some profiling applications installed there they are known to cause startup slowness. – MaLiN2223 Feb 01 '17 at 17:25
  • Do you Sing your assemblies? – Guillermo Hernandez Feb 01 '17 at 17:40
  • @MaLiN2223 According to your link, i have checked and i have no Software Restriction Policies applied.... I am currently reading the second link you provided. – Romeh Feb 01 '17 at 18:05
  • @GuillermoHernandez No my .exe is not signed. But if it's a sign probleme : why my app work correctly if i launch it with a big delay or manually? do you think it could be the probleme ? – Romeh Feb 01 '17 at 18:08
  • @GuillermoHernandez May be, you thinking about the opposite? Signed assemblies are starting slower? – Romeh Feb 01 '17 at 18:14
  • @MaLiN2223 About the profiling applications: There is no Anti-virus/ windows defender on the system. The OS is almost fresh. Only Ccleaner is installed. – Romeh Feb 01 '17 at 18:19
  • @Romeh I missed that you start this application during startup. I would advise you to start this application as [windows service](https://msdn.microsoft.com/en-us/library/d56de412(v=vs.110).aspx) if you do not have any GUI there - windows services are designed just for this task. What does your application do? Maybe we can extract parts of it so it will start as a few services? – MaLiN2223 Feb 01 '17 at 18:28
  • @MaLiN2223 I'll edit me own question, i have new infos. (comment are too limited ) – Romeh Feb 01 '17 at 18:41
  • Question edited with new infos. – Romeh Feb 01 '17 at 18:51
  • I also tried the simple test app with framework 3.5 client. same thing... app hang for 4 minutes then do the job. (6 minutes in total) – Romeh Feb 01 '17 at 20:00
  • @MaLiN2223 i have identified the problem, Thanks you for your help. – Romeh Feb 02 '17 at 08:44

1 Answers1

1

Okay..., I found the problem and the answer!

The problem is that "task scheduler" launch the applications with a priority set by default to "below to normal" .... Obviously, my application is slower because many high priority processes are launched at startup...

It is impossible to change the priority directly in task schedelur. It must be done by exporting the task in XML, modifying it, and re-importing it.

Original post here!

Thanks you.

Community
  • 1
  • 1
Romeh
  • 29
  • 8