80dB / AsyncNats

An async Nats.io client written using C# 8.0 language options
MIT License
6 stars 2 forks source link

performance tricks #6

Closed israellot closed 2 years ago

israellot commented 2 years ago

Here I'm adding a few tricks, mainly reducing allocations and virtual calls. Also adding a benchmark project to try understand where the bottlenecks are at various use cases.

So far, here is where it stands : image

It seems that we can flush data to NATS easily at 2M messages/second, but reading is imbalanced. I'm also puzzled as why bigger messages seem to perform better. My guess so far is at flow control.

Let me know your thoughts @80dB

israellot commented 2 years ago

Ok, I just realized that the benchmark was not realistic. Applications don't try to flood messages, and I believe the library shouldn't aim at optimizing throughput at a synthetic benchmark at the expense of everything else. I've tried to come up with a benchmark that evaluates performance at target throughputs and added to this branch.

Being more cooperative at the producer actually shows we can target to roundtrip close to 1M msg/s with acceptable latency.

image

80dB commented 2 years ago

I'll take a good look at this later in the week. I saw another project convert the first 4 bytes to an integer value and compare that instead of comparing byte arrays. Not sure if it's faster.

israellot commented 2 years ago

Closing in favor of https://github.com/80dB/AsyncNats/pull/7