我有一组生产者和消费者,两者都实现为zactors
。消费者绑定到 inproc
端点,每个生产者连接到其他所有消费者。
有一点,似乎ZeroMQ
无法再创建套接字或连接(我不确定是哪个)。
最小的工作示例:
#include "czmq.h"
void source_t(zsock_t * pipe, void *args);
void sink_t(zsock_t * pipe, void *args);
int main(int argc, char *argv[]){
zsys_init();
printf("Max sockets = %d\n", zsys_socket_limit());
int num_sources = atoi(argv[1]);
int num_sinks = atoi(argv[2]);
/** Create sinks */
zactor_t *sinks[num_sources];
for (int i = 0; i < num_sources; i++){
sinks[i] = zactor_new(sink_t, (void *)(&i));
assert(sinks[i]);
}
/** Create sources */
zactor_t *sources[num_sources];
for (int i = 0; i < num_sources; i++){
sources[i] = zactor_new(source_t, (void *)(&i));
assert(sources[i]);
zsock_send(sources[i], "i", num_sinks);
zsock_wait(sources[i]);
}
return 0;
}
void source_t(zsock_t * pipe, void *args){
const int id = *((int *)args);
zsock_signal(pipe, 0);
int num_sinks;
zsock_recv(pipe, "i", &num_sinks);
zsock_t * transmitters[num_sinks];
for (int i = 0; i < num_sinks; i++){
transmitters[i] = zsock_new(ZMQ_PUSH);
if(transmitters[i] == NULL){
printf( "Source %d could not create socket %d because %s\n",
id, i, strerror(errno)
);
assert(false); ////// Here's where it fails ___________________
}
int rc = zsock_connect(transmitters[i], "inproc://snk%d", i);
if (rc != 0){
printf("Source %d could not connect to sink %d because %s\n", id, i, strerror(errno));
assert(false);
}
}
zsock_signal(pipe, 0);
}
void sink_t(zsock_t * pipe, void *args){
const int id = *((int *)args);
zsock_t * receiver = zsock_new(ZMQ_PULL);
assert(receiver);
int rc = zsock_bind(receiver, "inproc://snk%d", id);
assert(rc == 0);
zsock_signal(pipe, 0);
while (true){
zsock_recv(receiver, "z");
}
}
我在Linux上运行了30个生产者和30个消费者,但它失败了。 我的打开文件限制是6144。
这是我的输出:
$ ZprocTest 30 30
Max sockets = 65535
Source 29 could not create socket 4 because Socket operation on non-socket
ZprocTest: ../src/ZprocTest.cpp:43: void source_t(zsock_t*, void*): Assertion `false' failed.
Aborted
是否还有其他人遇到类似问题或能否对此有所了解?