Skip to content
  • There are no suggestions because the search field is empty.

Measuring GC load in .NET

Check whether your .NET trading code allocates on the hot path.

Garbage collection pauses add latency and use CPU, so trading code should avoid allocating memory on its critical path. .NET gives you two calls to check this without a profiler.

  • GC.GetAllocatedBytesForCurrentThread() returns the bytes the current thread has allocated so far. Read it before and after a workload; the difference is what that workload allocated.
  • GC.CollectionCount(n) returns how many generation n collections (0, 1 or 2) have run. Compare the counts before and after.

How OnixS tested the .NET FIX Engine

  1. Start an initiator and an acceptor session in one process and send a few orders to warm up.
  2. Take allocation and collection readings, then send one million New Order Single messages (about 150 bytes each), waiting for the acceptor to echo each one.
  3. Record allocations separately on the sending and receiving threads, then take the readings again.

The test ran with memory, file and asynchronous file session storage. In every case allocated bytes and collection counts were zero, so the engine added no GC load.

Removing allocations makes a measurable difference. When OnixS did this in its CME MDP 3.0 handler, Gen 0 collections over 50,000 packets fell from 162 to none, median latency fell from 12.76 µs to 4.37 µs, and 99.9th percentile latency from 453.65 µs to 22.97 µs.

When you test your own code, warm up first, measure each thread on its own, and test on a machine set up like production.

 

 

 

Documentation: Garbage Collection Load Testing on ref.onixs.biz
Try it: Request a free 30-day evaluation
Questions? Email sales@onixs.biz