Home > Remote Desktop Services (RDS), Server Based Computing, Uncategorized, Virtual Desktop Infrastructure, Windows Server, XenApp, XenDesktop > Introducing ThreadLocker. A community tool for granular control of processes.

Introducing ThreadLocker. A community tool for granular control of processes.

Throughout this blog post, I’m going to be talking about Process Affinity and Process Priority. Understanding these definitions will help. I’m also only targetting server 2008 R2 and Windows 7 for this post.

An issue I see time and time again in Virtual Desktop Infrastructure and Server Based Computing environments is CPU spikes cause sessions to pause and stick. These CPU spikes can be caused by overcommitment or overzealous application usage and the vendors (Citrix, ThreadMaster, RES, Appsense, etc) have come to the rescue frequently with tools to reduce these events from occurring.

The problem with these solutions (Appsense excluded) is they are reactive, I.E. they take a number of seconds to identify a spike and respond by dropping the priority of the process or reducing the Users time on the processor.

These few seconds of high usage, reduce the amount of time the users applications and desktop session can spend on the processor, this reduction of resources cause the VDI desktop of the user to be completely unusable during the pause and ultimately resulting in complaining from the user community. Worse yet, if this is an SBC environment you now have all users on that server locked out!

And all this may sound a bit over the top, but its very easy to reproduce. For example, create a Microsoft Excel sheet and attempt to vlookup over a few thousand cells and watch the processor get chewed up. In this example, yes a vLookup across that many cells would be better served from a server based solution, but what’s stopping your users doing it?… Exactly.

Looking at SBC for a second:

With Server 2008 R2, the Fair Share CPU scheduling feature really is best (free) solution out there for CPU Utilisation management. The processor scheduling is far better than the Citrix equivalent and they also offer a feature (albeit, it feels unfinished) called Windows System Resource Manager to configure the processor affinity along with Process soft rules for performance management.

By setting these extremely intensive Multi-threaded applications to an affinity, we can “Lock” these processes to only run on certain processor cores, allowing the remaining cores to rebalance the rest of the workload. This ultimately, leaves the users session still responsive even if the application no longer responds. Allowing the user to continue working in other application until the intensive process is complete.

The problem with Windows System Resource Manager?

  • It’s a pain to configure on more than one system
  • It requires (yeuck) Windows Internal Database
  • It has been marked as “Depreciated” in Server 2012
  • If a user changes affinity, Resource manager doesn’t re adjust.
  • It still suffers from “pauses” or sluggishness when the Cpu is really being hammered.
So we’re back at the start again, Fair Share CPU scheduling is still the best free product, but how can we cap processes to cpu’s or drop the priority of a “Known Intensive” processes like Excel to stop these pauses?
What about VDI:
Well, there is nothing out there that’s free, move along.
End result:

This was my dillema recently with both XenApp & Xendesktop. Ultimately not happy to Pay for a solution, embrace a depreciated tool, or wash my hands of the problem, I decided to write my own tool, complimenting fair share CPU scheduling but allowing affinity and priority locking.

Introducing Threadlocker:

ThreadLocker has been written to help you target known problematic processes and deal with them pro actively.

Threadlocker also has the added benefit of dropping the priority of known grunty processes to idle, meaning the process will use as much CPU as it can, but any other higher priority process can interupt without sluggishness or pauses.

With ThreadLocker you can target these processes and set their Affinity number of processors they can run on:

Or their Process Priority to drop them out of the normal running context:

  • Threadlocker is light weight and scalable.
  • Threadlocker works flawlessly with Cpu Fair Share Scheduling, so even if a process is “ThreadLocked” the users running those applications will fair share on the designated cores.
  • Threadlockers configuration is xml based and can be copied down to the machine with Startup script or Group Policy preferences.
  • Threadlocker can be used in VDI environments where no other free solution is available.
  • Threadlocker will re-adjust priority, or affinity if the devious user tries to remove the restriction.

Threadlocker has been successfully tested on the following platforms:

  • XenApp 6.5
  • Windows Server 2008 R2 Service Pack 1
  • Windows 7 x64 Service Pack 1
Requirements:
  • Threadlocker Requires .Net Framework 3.5 sp1

Download:

Here

  1. Rasmus Rask
    June 14, 2012 at 8:51 am

    Looks VERY interesting and promising! Hope to get time to test this soon.

  2. gilwoodcs
    June 20, 2012 at 8:49 am

    Ah.. when I first saw this I thought that you\’d take over the code for threadmaster – but I see it\’s a different thing. Neat. One thing to remember tho\’ if you are limiting the CPU for a user, then the processes they are expecting to happen will take longer – which they whinge about.

    I don\’t know if the tool does this – but is it possible to log/alert that a process is being pegged back?

    • June 21, 2012 at 10:53 am

      Hi Andrew,

      This tool isnt a threadmaster derivative. Server 2008 R2 Fairshare does a good enough job.

      ThreadLocker is just for those cases where you need to lasso known, intensive applications that tend to run away with themselves.Agreed this will slow down the user, but it will also protect the other users.

      If you enable verbose logging, it will tell you every time it interacts with a process via the event logs.

  3. Mark
    February 11, 2013 at 10:14 pm

    Hi Andrew, great tool, just wondering if it has been tested on Windows server 2003?

    • February 12, 2013 at 10:17 am

      Hi Mark,

      It hasn’t, but no reason it wouldnt work.

      A

  4. Jose Ramon
    April 11, 2013 at 1:17 pm

    The download link is broken, thanks

    • April 11, 2013 at 2:36 pm

      It’s not.

    • Benjy
      April 11, 2013 at 4:26 pm

      It’s a box.com link – your company might block it.

      So far in my testing it’s a great utility – I think the only thing I would like is the ability to just give it a percentage of CPUs to use and then let it select which ones on its own.

  5. Michael
    May 16, 2013 at 6:10 pm

    Hello Andrew,

    Any idea why trying to set affinity on a process would produce an “Access to the path is denied” error? We’re trying to set affinity on printisolationhost.exe, on a terminal server, and getting this error from ThreadLocker when trying to do so.

    Thanks,
    Michael

    • May 16, 2013 at 6:39 pm

      Where are you getting this error? The event logs?

      • Michael
        May 16, 2013 at 6:49 pm

        Andrew, I just uploaded a screenshot of it here:

        https://sites.google.com/site/ixptier2/home/imagedump

        It’s the only file there currently! It’s popping up when trying to set the affinity. Other research today suggests maybe it’s due to that process needing access to the hardware layer, and so requiring equal access to all processors…?

        Thanks,
        Michael

      • May 16, 2013 at 6:53 pm

        Run as administrator? The config file is in the same directory as the service \ tool. Chances are you have uac disabled and you can’t write to that directory.

  6. Leo van Geel
    August 12, 2013 at 3:45 am

    Hi Andrew,. I installed Threadlocker and the services runs but it does not seem to do anything. I have tried everything e.g. Excel.exe or excel.exe *32 but no messages in the eventlog apart from that Threadlocker started successfully. Is version 1.1. from May 15 2012 still the latest? Also the screen above with the CPU affinities I cannot find.
    Appreciate any pointers how to set this up.

    Leo

    • August 17, 2013 at 7:32 am

      Hi Leo,

      Sorry for the delay. Drop me an email on andrew(at)Andrewmorgan.ie and we can review the problem.

  7. October 1, 2013 at 1:27 am

    I also cant get the threadlocker working for the XenApp 6.5 farm. I did set the rules and committed the changes but when i look in the task manager for the process, it is still unchanged in terms of the affinity and priority values.

    UAC is tuned OFF… please help. am i missing something?

  8. Tom
    January 30, 2014 at 3:22 pm

    How is it possible to use this to reduce IE9 cpu usage on each of our XenApp 6.5 servers??
    Would someone be willing to post a short example of how to configure this app??
    We are also running Flash 12.x as well…perhaps I should downgrade to Flash 11.x…
    Thank you, Tom

  9. Stefan
    March 25, 2014 at 8:46 am

    Great tool. I’ve set it up on all my RDSH servers to limit the cpu usage (affinity and priority) on the browsers who tend to go nuts on the CPU. Tom, I just put the name of the browser file but no ending (iexplore, chrome, firefox).. works great.

  1. July 9, 2012 at 11:52 am
  2. November 28, 2012 at 9:23 am
  3. January 4, 2013 at 12:52 pm
  4. August 17, 2013 at 3:10 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: