Allocations are cheap. garbage collections are not. According to profiling (ANTS) the sockets were the biggest cause of allocations, with 4 bots hunting the time spent on garbage collection was 3.6% of the total CPU time. The bufferpool now shows that the time spent running GC's is less than 1% of the total cpu time.Quote:
Stop it. This is ridiculous. Allocating memory for a buffer isn't expensive, and the socket system already allocates a buffer for you. You know what is expensive? Locking. Concurrency doesn't mean something can run in parallel. Having a "ConcurrentStack" popping off buffers means it's going to lock up there each time you want to get a buffer, which is far less efficient than just allocating stack memory
I agree on the locking part although concurrent collections are very well optimized they are slower than what you suggested. I don't see a bottleneck there though.
I had about 1 Gen0 GC every 2.5-3 seconds without the buffer pool, that's basically zero now.