To thread or not to thread? that is the question!

Every so often, I see myself pondering over this same question. And sometimes I pen my thoughts and conclusions down on a piece of paper , so that I don’t have to re-think later. This beautiful piece of paper, always seems to get lost among the clutter ( which I call organized stack) of papers  at my desk. So Threads or Processes?

 

Agreed, it comes down to the language of choice, but these days I use python and perl heavily in my scripts. And the GIL in python, always seems to make multithreading a daunting task on my multi-core machine.

 

Of course, we all know that multithreading has its advantages over multiprocessing- less footprint, stack size, much lighter , etc etc.. , but what happens with threading  behind the scenes , is what drives early programmers nuts, and make them conclude that threading arose from the dead sea.

The multithreading/multiprocessing debate…

In this particular project that I was working on, the ease of initiating a thread pool, lured me into the path of threads. Also, the fact that my underlying netsnmp c-library, was async, turned out to be an added bonus.

Yes, I started threading at first…

A little tidbit here- the scheduling of threads is actually done by the OS, and this turns out to be a disaster sometimes.

 

Yes, python relies on the OS to schedule threads. It just releases and re-acquires the GIL. Why not?  After all, the underlying OS is all about multithreading, and the guys who made it, should be experts at scheduling, right? Actually yes, the OS does a damn good job at this.

 

However, in a multicore machine, the OS is aware of all available cores. And chances are that it schedules the thread on another core…. boom! …. and you just created context-switching, and increased the overall time before the thread actually acquires the GIL. This is invariably what causes multithreading to give poorer than expected results…

 

So I went back to multiprocessing for this. Yes,  I know it has higher startup costs, significantly more memory…etc. But at the end , there isnt a lot of crazy context switching. And in this particular instance , I had 32 cores.  I was just planning to start the processes once, and then pipe their output in a subprocess stream. They worked fine!

…and then went back to processes

 

I’m not against threads, and I dont always favor processes either. But often times, we have to decide between the two based on the environment, the hardware, the throughput requirement, the desired speed of execution ( and a little bit of personal choice).  Its called “Using the right tool for the job”

New Mini-ESXI server

Ajay Divakaran, mini-esxi server 

Yes, chill-n-cool,running purely off of USB and NAS, currently the fastest node in my cluster, so quiet and cool( less than 26C inside the case ), that I have to brag about it…

 

Thought I’d share this configuration.Its storing/running all its VMs from NAS.

The Mini-ESXI Server Hardware Specs (845$):

>> Processor: Intel Xeon E3-1230 V2($290)
>> Motherboard : Intel S1200BTSR Micro ATX Server Motherboard LGA 1155 DDR3 1333 (190$)
>> Hypervisor Installation : 8Gig PNY USB-Flash drive ($8 @ staples)
>> VMs Storage : iOmega Home NAS ($100)
** – Upgraded later to DNS-320 that i got on sale at J&R. I needed the Raid!!
>> RAM : 32G ECC Unbuffered Dual Channel Crucial (120$)
>> Power: Intex PSU (450W, I think) 40$
>> Case : AeroCool m40 cube , MicroATX with Front-LCD Temperature display

And why these??

Well, my processor choice was down to either a core-i7 or a Xeon. And given that core-i7s are rather power-hungry for their performance, I settled on Xeon. Its TDP at 89Watts was lucrative, and in practice, with about 5 VMs running all the time, it consumes a little less than 30W (Cheaper than a lightbulb). And the quad-core ivy bridge, and 8MB L3-cache, sealed the deal.

 

I needed a server class motherboard, and after researching for a long while, i decided to go with one that I had already seen in use. The Intel S1200BTSR is a decent server motherboard, under 200$. Agreed, it comes with poor documentation, but seriously, how many of us look at that pamphlet of documentation that comes with motherboards? Aside from that, it performs well, runs cool, has a good FSB, and RAID (just if I ever decide to move my HDDs from NAS into this compute node)

 

The case was the instigator. I really liked the design and airflow-pattern of the Aerocool M40 cube. Besides, it has a front-panel LCD display indicating the temperature inside the chassis. Real cool.

 

A true beast of beauty

A few cable ties, to keep the wires from obstructing the airflow, and I was at the BIOS. Didnt overclock.. just turned on support for virtualization, and proceeded to install the esxi Hypervisor onto the USB (The little white guy you see standing up in the picture). Four minutes later, it was ready to start running my VMs.