danielwertheim

danielwertheim


notes from a passionate developer

Share


Sections


Tags


Disclaimer

This is a personal blog. The opinions expressed here represent my own and not those of my employer, nor current or previous. All content is published "as is", without warranty of any kind and I don't take any responsibility and can't be liable for any claims, damages or other liabilities that might be caused by the content.

New release of MyNatsClient - now 60% faster

Lately I've spent some time overhauling MyNatsClient (my open source .NET client for NATS). I've added support for TLS1.2 and fixed a few bugs but mostly been focusing on performance. And in doing so, I've managed to increase the performance with 60%. The scenario is a very simple case where I have one client requesting and one client responding to the requests. Just hammering away 100000 requests. Each request is waiting for the response before doing the next request. The results below are for a 512b payload.

As a reference, with the official client I'm getting 4458 request & responses per second (over 8900 msg/sec).

More information about what has changed exists in the release notes.

Moving forward, MyNatsClient has left "classic .NET" behind and currently targets .NET Standard 2.1. If "classic .NET" is a requirement for you, then I can recommend the official client. The official client supports both .NET4.5 as well as .NET Standard 1.6. I've also been involved in implementing support for RX in the official client. So if that was the main reason for you to use MyNatsClient, you should know that support for it now exists in the official client as well.

In future updates of MyNatsClient I hope you can expect to get support for new features of NATS 2.0, like JWT tokens etc. I've also decided that MyNatsClient will not support NATS-Streaming server. I will instead wait and see what happens to NATS JetStream as mentioned here:

Our next generation technology for doing Streaming, Work Queues and traditional Message Queues... - NATS blog

With this said. There's nothing left for me to-do, other than provide you with some simple usage sample of MyNatsClient and to wish you a happy new year.

Requester

var cnInfo = new ConnectionInfo("192.168.1.10");
var client = new NatsClient(cnInfo);

await _client.ConnectAsync();

var response = await client.RequestAsync(
    "getTemp",
    "stockholm@sweden");
    
Console.WriteLine($"Temp is '{response.GetPayloadAsString()}'.");

Responder

var cnInfo = new ConnectionInfo("192.168.1.10");
var client = new NatsClient(cnInfo);

await _client.ConnectAsync();

await client.SubAsync("getTemp", stream.Subscribe(msg => {
    client.Pub(msg.ReplyTo, getTemp(msg.GetPayloadAsString()));
}));

That's all. Again. Happy new year!

Cheers,

//Daniel

View Comments