Lock Free

| 2 Comments
I just ran my OpenSSL echo server test harness and ran the server under the deadlock tool. The results are interesting and show that the main source of lock contention on the server is for the lock that protects the buffer allocator. Every read or write requires a buffer to be allocated and released. The SSL server actually requires more than one buffer for each read and write as passing the data through the SSL connector causes further buffer allocations. Way back when we first started developing our server framework I boosted the performance quite a bit by having the buffer allocator maintain a pool of buffers rather than allocating and freeing a buffer each time it's asked. I think we can probably improve the performance even more by switching to lock free list implementation... Only more detailed profiling will tell for sure but it's certainly something I've added to the list of things to do...

I first looked at lock free algorithms for socket list management quite a while ago. At the time we managed to achieve our performance goals without needing them; plus, due to the design of the code at the time, it would have been difficult to plug in a lock free allocator rather than the existing allocator and the lock free implementations that I found weren't necessarily going to be as portable as I needed.

Now that the code has been refactored several times we have many more interfaces breaking the coupling and it should be possible to slip in an alternative buffer allocation strategy relatively easily.

The following are today's list of useful lock free links.

1) Ross Bencina provides a very useful review of available material.
2) The Microsoft SList API looks like it might be useful...
3) A paper that explains how lock free LIFOs and FIFOs can be implemented.
4) A lock free LIFO that's used in MidiShare.

2 Comments

Len,

Andrei Alexandrescu has done some interesting work in this area:

1) A. Alexandrescu. "Lock-Free Data Structures" (C/C++ Users Journal, 22(10), October 2004)

2) http://www.nwcpp.org/Downloads/2005/Lock-Free.pdf

I did some searching after your "lazy" post and came across the Intel Threading Tools package: http://www.intel.com/cd/software/products/asmo-na/eng/threading/tcwin/index.htm. There are some interesting docs there too.

Thanks for the links. I'd seen the Alexandrescu stuff before but it's good to read it again. The good thing about my buffer allocator is that it needn't ever delete anything for the life of the program, I can just pool the buffers for reuse. This simplifies things a little, I think, as I only need CAS to implement push/pop on a LIFO...

Leave a comment