Geek Speak

Efficient Multi-Threading

Performance is always important for users of The Server Framework and I often spend time profiling the code and thinking about ways to improve performance. Hardware has changed considerably since I first designed The Server Framework back in 2001 and some things that worked well enough back then are now serious impediments to further performance gains. That’s not to say that the performance of The Server Framework today is bad, it’s not, it’s just that in some situations and on some hardware it could be even better.

Useful undocumented Visual Studio compiler switches

Updated 1st February 2024 to fix broken links There are a couple of undocumented Visual Studio compiler switches which can be useful occasionally: /d1reportSingleClassLayout<name> - which produces a dump of the in memory layout of a given class /d1reportAllClassLayout - which does the same for ALL classes See here and here for more details. And if you liked that, you might find this collection of debugging tricks interesting.

Intrusive C++ containers

Recently, whilst continuing to improve the performance of various aspects of The Server Framework, I reached a point where I found I needed to replace some STL containers with intrusive containers which didn’t need to perform memory allocations during data insertion and removal. I had been toying with the idea of implementing custom containers for some time but have only recently had a pressing need for them. The STL provides some marvellously usable code which has changed the way people view container classes in C++.

Bitten by 'scoped static initialisation' in C++ - turn on Visual Studio's C4640 warning!

Today I discovered that C++ scoped static initialisation (function level) in Visual Studio is not done in a thread safe manner. It’s the kind of thing that I should have already known but I guess I assumed that since namespace level static initialisation was safe so was function level static initialisation. Unfortunately it’s not. If you read the MSDN documentation in a particular way you could decide that the docs say that it’s not; but it’s imprecise and unclear and I doubt that I did read the MSDN documentation anyway.

TIME_WAIT perfmon counters

I’ve built a small Windows Service which exposes perfmon counters to track sockets in TIME_WAIT state. It can be downloaded from the links later in this post. Back in 2011 I was helping a client look for issues in their systems caused by having too many sockets in a TIME_WAIT state (see here for why this can be a problem). This was affecting their connectivity. Rather surprisingly there seemed to be no way to track the number of sockets in TIME_WAIT using perfmon as there didn’t seem to be a counter exposed.

Visual Studio 2013 Preview - isprint() incorrectly classifies ' ' as printable for 'C' locale.

It seems that `isprint() is broken. The following program demonstrates the problem. In VS20013 it prints “test failed” in all previous versions of visual studio it prints “test passed”. From this reference: http://en.cppreference.com/w/cpp/string/byte/isprint it seems that VS2013 is broken. I’ve opened a Microsoft Connect issue for this. #include <ctype.h> #include <iostream> int main() { int c = 9; if (isprint(c)) { std::cout << "test failed" << std::endl; } else { std::cout << "test passed" << std::endl; } return 1; }

The perils of 'home office' RAID 5

I’ve had a little stand alone RAID device for several years now. It’s a Netgear ReadyNAS NV+ and it works quite nicely. I’m sure I could have something better but, I haven’t yet upgraded it apart from adding some memory and changing drives every now and then. I have a second ReadyNAS at my dad’s office and my office backs up critical data to that via rsync and a VPN; the one at his end does the same, though most data flows from me to him.

OpenSSL 1.0.1c key files are not compatible with OpenSSL 0.9.8x

A note to myself and my clients more than anything else… It seems that when you generate a key using a 1.x version of the openssl utility the blob looks like this: -----BEGIN ENCRYPTED PRIVATE KEY----- MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQI7BZmHKzGwtQCAggA etc... T+CaOPXRod3cKwZEgp0vkM+gpsLw0C6WVEdV01ZrgUsJ2DceYXaenHCjfZ7jwy84 LKk= -----END ENCRYPTED PRIVATE KEY----- whereas when you generate a key in exactly the same way with an 0.9.8 version of the utility the blob looks like this: -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,061B6446EB96A47B OFE9asOb689P0l6++Nwz0HYop4KdgKh6NFCzZV/kjp03VL2RW6beii2x70ikTLjs etc.

Building OpenSSL for x86 and x64 on Windows for side by side deployment

The Server Framework’s OpenSSL Option Pack integrates OpenSSL with my high performance server tool kit and gives you an IOCP based client or server that can handle many thousand concurrent connections with very few threads. The OpenSSL Option Pack has been around for over 10 years now and, as well as the SChannel Option Pack provides an easy way to add SSL or TLS to your clients and servers. Updated 26th April 2023 The latest scripts for OpenSSL 3.