问题
How does ZeroMQ ROUTER socket maintain its client connections internally.
The guide says each client gets a unique-ID, but it is not clear on:
- What counts as a client (each machine a different client or each connected app different??)
- Is there a limit on the number of requests received from a client?
The reason is, I am stress testing this code (from http://hintjens.com/blog:42) with ab:
#include "czmq.h"
int main(void)
{
zctx_t *ctx = zctx_new();
void *router = zsocket_new(ctx, ZMQ_ROUTER);
zsocket_set_router_raw(router, 1);
zsocket_set_sndhwm(router, 0);
zsocket_set_rcvhwm(router, 0);
int rc = zsocket_bind(router, "tcp://*:8080");
assert(rc != -1);
while (true)
{
// Get HTTP request
zframe_t *handle = zframe_recv(router);
if (!handle) break; // Ctrl-C interrupt
char *request = zstr_recv(router);
puts(request); // Professional Logging(TM)
free(request); // We throw this away
// Send Hello World response
zframe_send(&handle, router, ZFRAME_MORE + ZFRAME_REUSE);
zstr_send(router, "HTTP/1.0 200 OK\r\n""Content-Type: text/plain\r\n""\r\n""Hello, World!");
// Close connection to browser
zframe_send(&handle, router, ZFRAME_MORE);
zmq_send(router, NULL, 0, 0);
}
zctx_destroy(&ctx);
return 0;
}
When given the command ab -n 1000 -c 10 http://192.168.74.1:8080/
it occasionally completes fine, but many times it just hangs for some time and then either completes fine or fails with apr_pollset_poll: The timeout specified has expired (70007)
after some random number of messages (say, 300, 700 etc.)
The interesting part is, while ab is hanging (perhaps waiting for response), if you open a different connection from different machine/browser, it succeeds fine. How does a new connection from a different browser succeed, while ab is just hanging around?
So, wondering if this is a 'per connection limit' of ROUTER or something else going on. Note, the HWM set to be 0.
回答1:
I have been benchmarking too but with the python version of the same code as given here. [https://gist.github.com/malexer/8664997]. And its working fine, I even tested with 100000 requests and its fine too. May be you could give it a look. If you find the answer of your question may be you could inform us too.
the answer to your first questions is that each connected app counts as one client and have unique ID. I have designed a chat server where multiple client connects to router Socket--each with a unique ID.
来源:https://stackoverflow.com/questions/23305254/client-maintenance-in-zmq-router