负载测试ZeroMQ(ZMQ_STREAM),以查找它可以处理的最大同时用户数 [英] Load testing ZeroMQ (ZMQ_STREAM) for finding the maximum simultaneous users it can handle

查看:995
本文介绍了负载测试ZeroMQ(ZMQ_STREAM),以查找它可以处理的最大同时用户数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人在现实世界中是否有经过负载测试的ZMQ套接字的最大数量.可以处理的并发用户"(不是吞吐量)?看起来ZeroMQ的FD限制有一些严重的问题.

Does anyone have any real-world scenarios that load-tested ZMQ sockets for maximum no. of 'concurrent users' (not throughput) they can handle? Looks like ZeroMQ has some serious problems with FD limits.

场景是:有大量的Web服务器框架,它们拥有数百万个并发用户,他们可以处理-现在,如果ZeroMQ无法处理超过FD_SETSIZE no的情况.在任何时间的用户数量,这都是对可伸缩性的非常严格的限制(因为FD不仅是进程资源,而且还是机器资源,因此在同一台机器上生成新进程毫无意义).

The scenario is: there are numerous web-server frameworks out there that are boasting of millions of concurrent users they can handle - now if ZeroMQ cannot handle beyond FD_SETSIZE no. of users at any point of time, it is a very serious restriction on scalability (since FDs are not just process resources, but also machine resources, so no point in spawning a new process in the same machine).

为了验证,我正在尝试加载测试ZMQ_STREAM来查找它可以维持多少个并发用户.它是一个简单的"hello-world"响应服务器,该服务器仅侦听ZMQ_STREAM并为每个请求返回"hello world"(严格的接收方式,然后是发送方式).

To verify, I am trying to load test ZMQ_STREAM to find how many concurrent users it can sustain. Its a simple "hello-world" response server that just listens on ZMQ_STREAM and returns "hello world" for every request (in a strict receive followed by send style).

现在,在使用JMeter进行测试(使用users = 1000)时,命中断言:zmq_assert (fds.size () <= FD_SETSIZE).这意味着什么?该ZMQ持有FD_SETSIZE个FD吗?但是(按照下面的代码)每个连接都会立即打开和关闭,我看不到在任何时间点都可能同时打开多个FD的可能性.

Now, while testing with JMeter (using users=1000), hit the assertion: zmq_assert (fds.size () <= FD_SETSIZE). What does this signify? That ZMQ is holding FD_SETSIZE number of FDs? But (as per the below code) each connection is opened and closed immediately, I do not see how is it possible that more than few FDs could be simultaneously open at any point of time.

问题:如果是这种情况,那么任何基于ZMQ的应用程序将采用哪种方式? 实现百万用户并发连接? (除了 每个处理1000台机器的明显而毫无意义的解决方案 1000个用户,或者将FD_SETSIZE增加到一个非常大的数目)

Question: If this is the case, what is the way for any ZMQ based app to achieve million-user concurrent connections? (apart from the obvious and meaningless solution of having 1000 machines each handling 1000 users, or increasing the FD_SETSIZE to be an insanely large number)

任何人都不知道如何使用这些FD以及为什么使用这些FD,以及如何耗尽它们(更重要的是,其他框架(例如nginx node.js)没有这个问题),请阐明一下.

Anyone knows anything about how and why these FDs are used and how they get exhausted (and more importantly how other frameworks such as, nginx node.js do not have this problem) please throw some light.

服务器代码(如果需要的话)如下:

The server code, if it matters is below:

#include <zmq.h>
#include <assert.h>
#include <string.h>
#include <iostream>
int main(void)
{
    void *ctx = zmq_ctx_new();

    void *socket = zmq_socket(ctx, ZMQ_STREAM);
    int rc = zmq_bind(socket, "tcp://*:8080");
    uint8_t id[256];
    size_t id_size = 256;
    char msg[4096];
    size_t msg_size = 4096;
    int nCount = 0;
    char http_response[] =
        "HTTP/1.0 200 OK\r\n"
        "Content-Type: text/plain\r\n"
        "\r\n"
        "Hello, World!";
    int nResponseLen = strlen(http_response);
    while (1) {
        id_size = zmq_recv(socket, id, 256, 0);
        msg_size = zmq_recv(socket, msg, sizeof(msg), 0);
        msg[msg_size] = '\0';
        std::cout << ++nCount << " -----\n";

        zmq_send(socket, id, id_size, ZMQ_SNDMORE);
        zmq_send(socket, http_response, nResponseLen, ZMQ_SNDMORE);

        zmq_send(socket, id, id_size, ZMQ_SNDMORE);
        zmq_send(socket, 0, 0, ZMQ_SNDMORE);
    }
    zmq_close(socket);
    zmq_ctx_destroy(ctx);
    return 0;
}

使用JMeter,users = 1000

Using JMeter, users=1000

推荐答案

当您说每个连接立即打开和关闭"时,您是什么意思?您在stream套接字上绑定,该套接字在while循环中接受传入的请求,该循环永久运行并且从不关闭任何内容.永远不会到达循环后对zmq_close(socket);的调用.

What exactly do you mean when you say "each connection is opened and closed immediately"? You bind on a stream socket, which accepts incoming requests in the while loop, which runs perpetually and never closes anything. The call to zmq_close(socket); after the loop is never reached.

即使消息的最后部分显式使用ZMQ_SNDMORE,它也应保持连接打开以等待更多文本.我想大概是为了使少数客户端可以减少重复连接的开销.可能应该是:

Even the last part of the message explicitly uses ZMQ_SNDMORE, which should keep the connection open waiting for more text. Presumably to allow a small number of clients a lower overhead for repeated connections, I guess. It should probably be:

zmq_send(socket, 0, 0, 0);

我不知道这些问题中的哪一个会释放资源以允许更多的客户端(如果有的话),但是可能是对ZMQ的滥用(或至少被误导了),试图在其中编写HTTP服务器,或者尝试使其扩展到数百万并发的对等/客户端.

I don't know which of these issues would release the resources to allow a larger number of clients, if either, but probably it's an abuse of ZMQ (or at least misguided) to try and write an HTTP server in it or try to make it scale to millions of concurrent peers/clients.

node.js和nginx是基于事件的并发I/O系统,它们在架构上与ZMQ显着不同,并且可以解决不同的问题.试图将ZMQ纳入其中的做法是错误的.您可能想要的是将node.js与socket.io一起使用,或者如果将其用于HTTP,则只需使用其本机http模块即可.

node.js and nginx are event based concurrent I/O systems, they are significantly different architecturally from ZMQ, and they are made to solve different problems. Trying to make ZMQ into them is going about things the wrong way. What you probably want is to use node.js with socket.io, or if you're using it for HTTP then just use it's native http module.

这篇关于负载测试ZeroMQ(ZMQ_STREAM),以查找它可以处理的最大同时用户数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆