I have 2 use cases.
1. Clients which wiat for ack to publish next message
2. Clients which publish without needing any ack
Let me elaborate
2. *Clients which publish without needing ack: *
In this use case, a client publishes data as fast as it can in one
direction and server simply discards the output. Enclosed are files
zserver.cpp and zclient.cpp which accomplishes it.
What is puzzling to me is that i have 1Gb network, but based on the numbers
published by the zclient.cpp, i am able to publish 5GB in one second?
With message size of 1KB, i am able to publish 5157783 messages per second.
How is this possible ?
1. *Clients which wait for ack to publish next message*
In this use case, client publishes next message ONLY after it gets a
message from server. So essentially client waits for RTT to publish next
message.
The same application as above in pt2, just using different socket type, now
client can barely publish 1k messages per second..
This is shown by file zclient-ack.cpp and zserver-ack.cpp
Can someone please explain the odd behavior?
Thank you,
Jim
#include <string>
#include <iostream>
#include "zmq.hpp"
#include "boost/chrono.hpp"
typedef boost::chrono::duration<long, boost::milli> milliseconds;
std::string * makeString(int i);
int main()
{
zmq::context_t context(1);
std::cout << "About to create a socket" << std::endl;
zmq::socket_t socket(context, ZMQ_PUB);
std::cout << "Socket created " << std::endl;
long numOfMsgs =0;
int size = 1024;
std::string *s = makeString(size);
std::cout << "Message is " << std::endl;
std::cout << *s << std::endl;
std::cout << "String length is " << s->length() << std::endl;
zmq::message_t request(size);
memcpy((void *) request.data(),(void *) s, 1024);
socket.connect("tcp://omhq19dd:5555");
boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now();
milliseconds ms(10000);
boost::chrono::system_clock::time_point end = start + ms;
do
{
socket.send(request);
// std::cout << "Message send "<< std::endl;
// zmq::message_t response;
// socket.recv(&response);
numOfMsgs++;
} while(boost::chrono::system_clock::now() < end);
std::cout << "Number of messages send in ten sec: " << numOfMsgs << std::endl;
return 0;
}
std::string * makeString(int i)
{
char data[1024];
for(int j=0;j<i;j++)
{
data[j] = 'a';
}
std::string *a = new std::string(data, 1024);
return a;
}
#include <string>
#include <iostream>
#include "zmq.hpp"
#include "boost/chrono.hpp"
typedef boost::chrono::duration<long, boost::milli> milliseconds;
std::string * makeString(int i);
int main()
{
zmq::context_t context(1);
std::cout << "About to create a socket" << std::endl;
zmq::socket_t socket(context, ZMQ_REQ);
std::cout << "Socket created " << std::endl;
long numOfMsgs =0;
int size = 1024;
std::string *s = makeString(size);
std::cout << "String length is " << s->length() << std::endl;
zmq::message_t request(size);
memcpy((void *) request.data(),(void *) s, 1024);
socket.connect("tcp://omhq19dd:5555");
boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now();
milliseconds ms(10000);
boost::chrono::system_clock::time_point end = start + ms;
do
{
socket.send(request);
// std::cout << "Message send "<< std::endl;
zmq::message_t response;
socket.recv(&response);
numOfMsgs++;
} while(boost::chrono::system_clock::now() < end);
std::cout << "Number of messages send in ten sec: " << numOfMsgs << std::endl;
return 0;
}
std::string * makeString(int i)
{
char data[1024];
for(int j=0;j<i;j++)
{
data[j] = 'a';
}
std::string *a = new std::string(data, 1024);
return a;
}
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
while(true)
{
zmq::message_t request;
zmq::message_t response(5);
socket.recv(&request);
//memcpy((void *) response.data(), "World", 5);
//socket.send(response);
}
return 0;
}
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
while(true)
{
zmq::message_t request;
zmq::message_t response(5);
socket.recv(&request);
memcpy((void *) response.data(), "World", 5);
socket.send(response);
}
return 0;
}
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev