ZMQ ROUTER客户端维护 [英] Client maintenance in ZMQ ROUTER

查看:110
本文介绍了ZMQ ROUTER客户端维护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ZeroMQ ROUTER 套接字如何在内部维护其客户端连接.

How does ZeroMQ ROUTER socket maintain its client connections internally.

指南说每个客户都有一个唯一的 ID,但不清楚:

The guide says each client gets a unique-ID, but it is not clear on:

  1. 什么算作客户端(每台机器不同的客户端或每个连接的应用程序不同??)
  2. 从客户端收到的请求数量是否有限制?

原因是,我正在对此代码进行压力测试(来自 http://hintjens.com/blog:42) 与 ab:

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;
}

当给定命令 ab -n 1000 -c 10 http://192.168.74.1:8080/ 它偶尔可以正常完成,但很多时候它只是挂了一段时间然后要么正常完成或失败,apr_pollset_poll: The timeout specified has expired (70007) 经过一些随机数量的消息(例如,300、700 等)

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.)

有趣的部分是,当 ab 挂起时(可能在等待响应),如果您从不同的机器/浏览器打开不同的连接,它会成功.来自不同浏览器的新连接如何成功,而 ab 只是闲逛?

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?

所以,想知道这是 ROUTER 的每个连接限制"还是其他原因.注意,HWM 设置为 0.

So, wondering if this is a 'per connection limit' of ROUTER or something else going on. Note, the HWM set to be 0.

推荐答案

我也进行了基准测试,但使用的是与此处给出的相同代码的 Python 版本.[https://gist.github.com/malexer/8664997].它工作正常,我什至用 100000 个请求进行了测试,它也很好.也许你可以看看.如果您找到问题的答案,您也可以通知我们.

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.

您的第一个问题的答案是每个连接的应用程序都算作一个客户端并具有唯一 ID.我设计了一个聊天服务器,其中多个客户端连接到路由器 Socket——每个客户端都有一个唯一的 ID.

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.

这篇关于ZMQ ROUTER客户端维护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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