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?