提高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
最满意答案
简单来说,您可以根据单击的单元格显示警报视图。 所以
-(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]; }
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
免责声明:我不为苹果公司工作或说话,所以这是我的看法: 我不能说主要的开发商,但在我的小组中,我们已经使用Objective-C ++来集成C ++库,并且正如你建议用C ++编写后端一样。 正如@alxp提到的那样,像跨语言边界的异常处理这样的事情是痛苦的,但只要稍加规划,就可以避免大部分这些痛苦。 对于有经验的C ++开发人员来说,这些收益可能是值得的。 在支持方面,我认为你可以认为目前状态下的支持不会很快消失。 它是GCC代码库的一部分, Clang工具链(Apple的下一个编译器工具链)完全支持Ob ...
-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我假设clearText方法是您创建的用于删除两个字段中文本的自定义方法吗? 所以它不是一个IBAction,它应该是一个无效的方法: - (void)clearText { Spelare1Slag1.text = @""; Spelare1Slag2.text = @""; } 现在,您只需在UIAlertView委托方法中执行下列操作,即调用clearText方法: - (void)alertView: (UIAlertView *)alertView clickedButtonAtIndex:(N ...
-
Else声明中的AlertView(AlertView in Else Statement)[2022-04-19]
这应该非常简单。 只需在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 ... -
如何通过单击tableViewCell获取AlertView(Objective-c)(how to get a AlertView by click a tableViewCell(Objective-c))[2023-08-02]
简单来说,您可以根据单击的单元格显示警报视图。 所以 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.row == 0) { //Change 0 to the row you want [self showAlertView]; } } 然后在一个单独的功能 -(void)showAlertView { ... -
防止AlertView解雇(Prevent AlertView dismissal)[2024-02-10]
这可能违反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 ...