OmG
OmG

Reputation: 18838

Performance Issue of Sending Large Object using NetMQ Multipart Message

I'm sending large object using the following code in C# (NetMQ):

var client = new DealerSocket("<connection String>");
var serializedData = new string('*', 500000);
var message = new List<byte[]>();
message.Add(Encoding.UTF8.GetBytes("BulkSend"));
message.Add(Encoding.UTF8.GetBytes(serializedData));
client.TrySendMultipartBytes(TimeSpan.FromMilliseconds(3000), message);

This code is taking 90% of CPU usage if it would be used in a high traffic (for example 10MB message per second). After some research, I've tried the two following codes. First of all, I removed the first frame ("Bulk Send"):

var client = new DealerSocket("<connection String>");
var serializedData = new string('*', 500000);
var message = new List<byte[]>();
message.Add(Encoding.UTF8.GetBytes(serializedData));
client.TrySendMultipartBytes(TimeSpan.FromMilliseconds(3000), message);

Surprisingly, the performance was improved. Secondly, I rearrange two frames. I mean moving the large frame to the first. Like the following:

var client = new DealerSocket("<connection String>");
var serializedData = new string('*', 500000);
var message = new List<byte[]>();
// change the order of two following codes
message.Add(Encoding.UTF8.GetBytes(serializedData));
message.Add(Encoding.UTF8.GetBytes("BulkSend"));

client.TrySendMultipartBytes(TimeSpan.FromMilliseconds(3000), message);

Again surprisingly the performance was improved!

What's the problem? How can I improve the performance? What about using zproto on netmq? Is there any proper document around that?

Upvotes: 2

Views: 1883

Answers (2)

OmG
OmG

Reputation: 18838

As I found, there is a problem with sending multipart message. You can see this link http://hintjens.com/blog:84. And probably encode your message into one message and then sending it!

Upvotes: 1

iiwaasnet
iiwaasnet

Reputation: 51

High CPU/low performance might be because of GC and memory allocations. I tried to send the same message size with my framework, which uses NetMQ, with server and client working on same machine. In case the client was waiting for the response before sending another message to server I achieved 60K msg/sec. Nevertheless, if the client was sending hundreds of messages in parallel, CPU was as well high and throughput was tens of messages per sec. At some point in time I've even got OutOfMemoryException. Would be good, if you post the complete code.

UPD: Sorry, I measured it wrong. With with either 100 messages sent in parallel or just one the performance is just 120 msg/sec

Upvotes: 0

Related Questions