Try PubSub+

PERFORMANCE! Why you should use Message.reset() in Solace APIs..!

AaronAaron Member, Moderator, Employee Posts: 127 Solace Employee
edited October 16 in Tips and Tricks

Hi Developers! Want to go fast? Faster, anyway? Read on...

I'm just putting the finishing touches on a new bunch of Solace Java (JCSMP) samples, and have been doing a bit of performance testing with them. They are still meant to be fairly simple and straightforward, and don't try to maximize absolute throughput performance, but they're pretty quick. When publishing Direct messages in a loop, I was wondering what the difference would be between creating new Message objects each time, or reusing the same ones and calling reset() on each loop, and reusing it on the next loop. Well...

Creating new Message object each loop

Published msgs/s: 251,419
Published msgs/s: 255,510
Published msgs/s: 256,729
Published msgs/s: 258,469
Published msgs/s: 256,312

Using Message.reset() on each loop

Published msgs/s: 323,841
Published msgs/s: 316,270
Published msgs/s: 327,877
Published msgs/s: 336,641
Published msgs/s: 325,477
Published msgs/s: 326,037

Huh! About a 25% increase in speed. Not bad..! Also, when Java's GC would start to kick in, that would definitely periodically impact performance, having to clean up all these unused Message objects.

Technical notes: JCSMP API, single thread, Direct messages, 100 byte payload, dynamic topics, Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz, 1 GbE LAN to Solace broker
Code is here:


  • TamimiTamimi Member, Administrator, Employee Posts: 65 admin

    I can picture the messages flowing through the broker like this

  • TomFTomF Member, Employee Posts: 116 Solace Employee

    Very useful bit of research, @Aaron. I wonder what the difference would be in the C API? Obviously not re-using messages in C would look a like a memory leak, which you would (hopefully) spot sooner or later, but all those extra mallocs would definitely slow things down.

Sign In or Register to comment.