挑战在于简单地从PHP复制并推送数百个http请求/秒到单个C ++ PULL服务器。 PULL服务器只是将请求写入STDOUT。
在负载下,系统处理负载,直到PULL服务器耗尽其打开文件限制10,000,然后它停止接受连接并在100%CPU使用率时自行固定。
服务器的内容看起来像这样(删除所有错误捕获代码:)
// Crank up zmq
ctx = zmq_ctx_new ();
// Pull socket type in the pipeline pattern
s = zmq_socket (ctx, ZMQ_PULL);
rc = zmq_bind (s, socketdsn);
// Create a buffer to store messages
char buffer[MAX_BUFFER] = {0};
while (true) {
// Get the message
rc = zmq_recv (s, buffer, MAX_BUFFER, 0);
// Tack a null at the end of the string so printf will work...
buffer[rc] = 0;
// Output the string.
printf("%s\n", buffer);
}
rc = zmq_close (s);
rc = zmq_term (ctx);
PHP PUSH服务器的内容如下所示:
$dsn = "tcp://localhost:5555";
// Create context
$ctx = new ZMQContext();
$socket = $ctx->getSocket(ZMQ::SOCKET_PUSH, 'my socket');
$socket->connect($dsn, true);
$rc = $socket->send($message);
$socket->close($dsn);
我的猜测是PULL服务器必须在收到消息后手动关闭它的连接。 PUSH客户端是一个PHP进程,PULL服务器永远不会看到它的另一条消息,关闭连接是安全的。但似乎没有适当的功能。有什么想法吗?