首页 \ 问答 \ 提高ZeroMQ REQ / REP性能(Improve ZeroMQ REQ/REP performance)

提高ZeroMQ REQ / REP性能(Improve ZeroMQ REQ/REP performance)

我使用的是ZeroMQ 3.2.3和CZmq 1.4.1。 我尝试了“Hello world”示例。 该示例( https://github.com/imatix/zguide/tree/master/examples/C )在使用10个并发客户端时,允许我每秒钟在Intel i7上交换最多12500条消息(总计8 GB RAM,总计8个核心)在本地主机上(Ubuntu 13.04)。

我读了ZeroMQ可以处理更多。 我做错了什么,或者错过了什么?

以下是示例代码:

//  Hello World server

#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>

int main (void)
{
    //  Socket to talk to clients
    void *context = zmq_ctx_new ();
    void *responder = zmq_socket (context, ZMQ_REP);
    int rc = zmq_bind (responder, "tcp://*:5555");
    assert (rc == 0);

    while (1) {
        char buffer [10];
        zmq_recv (responder, buffer, 10, 0);
        //printf ("Received Hello\n");
        zmq_send (responder, "World", 5, 0);
        //usleep (1);          //  Do some 'work'
    }
    return 0;
}



//  Hello World client
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

int main (void)
{
    printf ("Connecting to hello world server...\n");
    void *context = zmq_ctx_new ();
    void *requester = zmq_socket (context, ZMQ_REQ);
    zmq_connect (requester, "tcp://localhost:5555");

    int request_nbr;
    for (request_nbr = 0; request_nbr != 100000; request_nbr++) {
        char buffer [10];
//        printf ("Sending Hello %d...\n", request_nbr);
        zmq_send (requester, "Hello", 5, 0);
        zmq_recv (requester, buffer, 10, 0);
//        printf ("Received World %d\n", request_nbr);
    }
    zmq_close (requester);
    zmq_ctx_destroy (context);
    return 0;
}

谢谢 !


I'm using ZeroMQ 3.2.3 and CZmq 1.4.1. I gave the "Hello world" sample a try. That sample (https://github.com/imatix/zguide/tree/master/examples/C), when using 10 concurrent clients, allows me to exchange at most 12500 messages per second on a Intel i7 (8 GB RAM, total 8 cores) on the localhost (Ubuntu 13.04).

I read ZeroMQ could handle much more. Am I doing something wrong, or missing something ?

Here is the sample code :

//  Hello World server

#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>

int main (void)
{
    //  Socket to talk to clients
    void *context = zmq_ctx_new ();
    void *responder = zmq_socket (context, ZMQ_REP);
    int rc = zmq_bind (responder, "tcp://*:5555");
    assert (rc == 0);

    while (1) {
        char buffer [10];
        zmq_recv (responder, buffer, 10, 0);
        //printf ("Received Hello\n");
        zmq_send (responder, "World", 5, 0);
        //usleep (1);          //  Do some 'work'
    }
    return 0;
}



//  Hello World client
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

int main (void)
{
    printf ("Connecting to hello world server...\n");
    void *context = zmq_ctx_new ();
    void *requester = zmq_socket (context, ZMQ_REQ);
    zmq_connect (requester, "tcp://localhost:5555");

    int request_nbr;
    for (request_nbr = 0; request_nbr != 100000; request_nbr++) {
        char buffer [10];
//        printf ("Sending Hello %d...\n", request_nbr);
        zmq_send (requester, "Hello", 5, 0);
        zmq_recv (requester, buffer, 10, 0);
//        printf ("Received World %d\n", request_nbr);
    }
    zmq_close (requester);
    zmq_ctx_destroy (context);
    return 0;
}

Thank you !


原文:https://stackoverflow.com/questions/17054562
更新时间:2022-04-14 21:04

最满意答案

简单来说,您可以根据单击的单元格显示警报视图。 所以

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0) { //Change 0 to the row you want 
        [self showAlertView];
    }
}

然后在一个单独的功能

-(void)showAlertView {
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"YOUR TITLE"
                                                                         message:@"AND A MESSAGE OF YOUR ALERT"
                                                                         preferredStyle:UIAlertControllerStyleAlert];
     //We add buttons to the alert controller by creating UIAlertActions:
     UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"YOUR BUTTON TITLE"
                                                   style:UIAlertActionStyleDefault
                                                 handler:nil]; //You can use a block here to handle a press on this button
     [alertController addAction:actionOk];
     [self presentViewController:alertController animated:YES completion:nil];
}

编辑*********

根据你的评论

如果要根据单元格标识符显示警报,则可以在didSelectRowAtIndexPath方法中使用类似的内容。

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

if([cell.reuseIdentifier isEqualToString:@"CELLIDENTIFIER"]){
    [self showAlertView];
}

In simple terms you can show an Alert View based on the cell clicked. So

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0) { //Change 0 to the row you want 
        [self showAlertView];
    }
}

Then in a separate function

-(void)showAlertView {
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"YOUR TITLE"
                                                                         message:@"AND A MESSAGE OF YOUR ALERT"
                                                                         preferredStyle:UIAlertControllerStyleAlert];
     //We add buttons to the alert controller by creating UIAlertActions:
     UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"YOUR BUTTON TITLE"
                                                   style:UIAlertActionStyleDefault
                                                 handler:nil]; //You can use a block here to handle a press on this button
     [alertController addAction:actionOk];
     [self presentViewController:alertController animated:YES completion:nil];
}

EDIT*********

Based on your comment

If you want to display the alert based on the cell identifier then you could use something like this inside your didSelectRowAtIndexPath method.

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

if([cell.reuseIdentifier isEqualToString:@"CELLIDENTIFIER"]){
    [self showAlertView];
}

相关问答

更多
  • 免责声明:我不为苹果公司工作或说话,所以这是我的看法: 我不能说主要的开发商,但在我的小组中,我们已经使用Objective-C ++来集成C ++库,并且正如你建议用C ++编写后端一样。 正如@alxp提到的那样,像跨语言边界的异常处理这样的事情是痛苦的,但只要稍加规划,就可以避免大部分这些痛苦。 对于有经验的C ++开发人员来说,这些收益可能是值得的。 在支持方面,我认为你可以认为目前状态下的支持不会很快消失。 它是GCC代码库的一部分, Clang工具链(Apple的下一个编译器工具链)完全支持Ob ...
  • 我假设clearText方法是您创建的用于删除两个字段中文本的自定义方法吗? 所以它不是一个IBAction,它应该是一个无效的方法: - (void)clearText { Spelare1Slag1.text = @""; Spelare1Slag2.text = @""; } 现在,您只需在UIAlertView委托方法中执行下列操作,即调用clearText方法: - (void)alertView: (UIAlertView *)alertView clickedButtonAtIndex:(N ...
  • 这应该非常简单。 只需在else语句中添加以下简短示例代码: let alert = UIAlertController(title: "Your title", message: "Your message", preferredStyle: .Alert) alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil)) presentViewController(alert, animated: true, compl ...
  • 简单来说,您可以根据单击的单元格显示警报视图。 所以 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.row == 0) { //Change 0 to the row you want [self showAlertView]; } } 然后在一个单独的功能 -(void)showAlertView { ...
  • 这可能违反HIG指导原则,不会解雇UIAlertView。 解决方法:我不知道应用程序中发生了什么,但为了实现此目的,您可以执行的操作是关闭AlertView,然后检查textView的文本是否已设置。 如果它设置为零,则再次调出alertview! That might be against HIG Guidelines to NOT to dismiss an UIAlertView. WORKAROUND : I don't know what goes on in your app, but to ...
  • 您需要创建目标目录,然后枚举源目录中的所有文件并将其复制到目标 。 子目录会让事情变得复杂一点。 如果你有它们,你的枚举代码应该是递归的 。 UDATE: 这是代码示例。 请注意,它不处理子目录。 NSString *sourcePath = @"..."; NSString *destPath = @"..."; NSFileManager *fm = [NSFileManager defaultManager]; [fm createDirectoryAtPath:destPath withInter ...
  • 未为alertView分配委托。 UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Announcement" message: @"No Connection" delegate: self ...
  • 看一下WebKit框架中的WebView组件。 如果要显示网站目录中的所有文件,则可以在其上设置目录启用为true,然后使用WebView获取页面。 如果需要过滤返回的列表,则可以在WebView委托方法中执行此操作。 http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/Reference/Reference.html Take a look at the Web ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。