• High memory consumption in WaWorkerHost.exe

    Published by Jorge Rowies on January 9th, 2012 9:08 pm under Windows Azure, Worker Roles

    No Comments

    When the memory usage of the WaWorkerHost.exe process starts going up without apparent reason, and you are using Tasks in your worker role, it might be the time to check for unhandled exceptions and start handling them properly.

    Throwing exceptions from Tasks in a worker role and NOT properly handling them:

        public class WorkerRole : RoleEntryPoint
        {
            public override void Run()
            {
                while (true)
                {
                    Task.Factory.StartNew(() => { throw new NotImplementedException(); });
                    Thread.Sleep(100);
                }
            }
        }
    

    Might cause this memory consumption in the WaWorkerHost.exe process:

    NOTE: WaWorkerHost.exe is the process in charge of hosting your worker roles when running in the emulator.

    Below you can find one way to handle exceptions that are thrown in Tasks.

        public class WorkerRole : RoleEntryPoint
        {
            public override void Run()
            {
                while (true)
                {
                    Task.Factory.StartNew(
                        () =>
                        {
                            throw new NotImplementedException();
                        })
                        .ContinueWith((t) =>
                        {
                            Trace.WriteLine(string.Format("Exception in Worker Role: {0}",
                                t.Exception.InnerException.ToString()));
                        },
                        TaskContinuationOptions.OnlyOnFaulted);
    
                    Thread.Sleep(100);
                }
            }
        }
    

    Tags: ,

  • Leave a comment

    Your email address will not be published.

Archives

@jrowies