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

 

ThreadlockerThroughout 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

Related Posts

UnSticking an AppDisk provisioning task in XenDesk... Here's a wee little bug I've no idea how i created, but managed to clear it out anyway. After creating an AppDisk, it got a little stuck. I tried d...
ThreadLocker 2.1 is available. Shortly after it's initial launch and great reception! I'm proud to announce the general availability of ThreadLocker 2.1. This is a minor up...
ThreadLocker 2.0 is live! Back in 2012 I wrote a utility called "ThreadLocker" for dealing with CPU heavy processes or multi threaded processes that have a nasty tendency to ca...

24 Comments About “Introducing ThreadLocker. A community tool for granular control of processes.

  1. gilwoodcs

    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?

    Reply
    1. Andrew Morgan

      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.

      Reply
  2. Pingback: The Curious Case of High CPU usage on Login with Citrix XenApp. « AndrewMorgan.ie

  3. Pingback: CPU scheduling and memory optimizations solutions compared Part 1 of 2 CPU

  4. Pingback: Using ThreadLocker to control runaway applications | Bram Wolfs blog

    1. Benjy

      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.

      Reply
  5. Michael

    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

    Reply
        1. Andrew Morgan

          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.

          Reply
  6. Leo van Geel

    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

    Reply
  7. Pingback: CPU scheduling and memory optimizations solutions compared

  8. Lal Mohan

    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?

    Reply
  9. Tom

    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

    Reply
  10. Stefan

    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.

    Reply
  11. Pingback: ThreadLocker 2.0 is live! | Andrew Morgan

  12. Diego

    This is Brilliant I was looking for a solution on a terminal server with high CPU usage for months and this solve it in 2 minutes very happy with the outcome highly recommended…

    Reply

Leave a Reply