My Problem, Briefly
I made a change to my library, now it's much slower but I can't figure out where it spends all that additional time. Profiling reports are not helping. Please help me figure out what the reason might be.
Some Context
I made a Redis client-library called Hedis and have a benchmark program for it. Now, I made some internal changes to the library, to clean up the architecture. This caused performance (in Redis-requests per second, as measured by said benchmark) to drop by a factor of about 2.5.
The benchmark opens 50 network connections to a Redis server on localhost. The connections are handled differently between the two versions:
- The fast version uses one thread per connection (thus, the benchmark has 50 threads running concurrently). It reads from the socket
handle by using
unsafeInterleaveIO(I describe my approach in broad strokes in a blog post here). I was a bit unhappy with the architecture, hence I changed things to - the slow version which uses three threads per connection. They communicate via two
Chans (150 threads running in the benchmark).
Some more information that might be relevant:
- Compiled with GHC 7.2.2.
- The benchmark program is unchanged between the two versions, so network traffic is the same.
- Both versions use the single-threaded runtime (compiled without
-threaded). - All threads are created by calling
forkIO. Not the more expensiveforkOS.
Profiling Results
Profiling does not give me a clear reason for the drop in performance. According to the profiling report, both versions spend more than 99% of their time in System