Dive into ØMQ (aka ZeroMQ), the smart socket library that gives you fast, easy, message-based concurrency for your applications. With this quick-paced guide, you’ll learn hands-on how to use this scalable, lightweight, and highly flexible networking tool for exchanging messages among clusters, the cloud, and other multi-system environments.
Dive into ØMQ (aka ZeroMQ), the smart socket library that gives you fast, easy, message-based concurrency for your applications. With this quick-paced guide, you’ll learn hands-on how to use this scalable, lightweight, and highly flexible networking tool for exchanging messages among clusters, the cloud, and other multi-system environments.
ØMQ maintainer Pieter Hintjens takes you on a tour of real-world applications, using extended examples in C to help you work with ØMQ’s API, sockets, and patterns. Learn how to use specific ØMQ programming techniques, build multithreaded applications, and create your own messaging architectures. You’ll discover how ØMQ works with several programming languages and most operating systems—with little or no cost.
Learn ØMQ’s main patterns: request-reply, publish-subscribe, and pipeline
Work with ØMQ sockets and patterns by building several small applications
Explore advanced uses of ØMQ’s request-reply pattern through working examples
Build reliable request-reply patterns that keep working when code or hardware fails
Extend ØMQ’s core pub-sub patterns for performance, reliability, state distribution, and monitoring
Learn techniques for building a distributed architecture with ØMQ
Discover what’s required to build a general-purpose framework for distributed applications
作者简介
· · · · · ·
Pieter Hintjens started his first business making video games 30 yearsago and has been building software products since then. Taking as hisprinciple, "the real physics of software is the physics of people", hefocuses now on building communities through "Social Architecture",writing, and helping others use ZeroMQ profitably.
For two years he was president of the FFII, a large NG...
Pieter Hintjens started his first business making video games 30 yearsago and has been building software products since then. Taking as hisprinciple, "the real physics of software is the physics of people", hefocuses now on building communities through "Social Architecture",writing, and helping others use ZeroMQ profitably.
For two years he was president of the FFII, a large NGO fightingsoftware patents. He was CEO of Wikidot, founder of the EuropeanPatent Conference, and founder of the Digital Standards Organization.
Pieter speaks English, French, Dutch, and bits and pieces of a dozenother languages. He plays with a West African drum group in Brusselsand is becoming a licensed NRA pistol instructor in Texas. Pieterlives with his beautiful wife and three lovely children in Brussels,Belgium and travels extensively.
There are three main open source development patterns. The first is the large firm dumping code to break the market for others. This is the Apache Foundation model. The second is tiny teams or small firms building their dreams. This is the most common open source model, which can be very successful commercially. The last is aggressive and diverse communities that swarm over a problem landscape. This is the Linux model, and the one to which we aspire with ØMQ. (查看原文)
If there's one lesson we've learned from 30+ years of concurrent programming, it is: just don't share state.
You should follow some rules to write happy multithreaded code with ZeroMQ:
- Isolate data privately within its thread and never share data in multiple threads. The only exception to this are ZeroMQ contexts, which are threadsafe.
- Stay away from the classic concurrency mechanisms like as mutexes, critical sections, semaphores, etc. These are an anti-pattern in ZeroMQ applications.
- Create one ZeroMQ context at the start of your process, and pass that to all threads that you want to connect via inproc sockets.
- Use attached threads to create structure within your application, and connect these to their parent threads using PAIR sockets over inproc. The pattern is: bind paren... (查看原文)
If there's one lesson we've learned from 30+ years of concurrent programming, it is: just don't share state. You should follow some rules to write happy multithreaded code with ZeroMQ: - Isolate data privately within its thread and never share data in multiple threads. The only exception to this are ZeroMQ contexts, which are threadsafe. - Stay away from the classic concurrency mechanisms like ...
2016-03-19 23:03:56
If there's one lesson we've learned from 30+ years of concurrent programming, it is: just don't share state.
You should follow some rules to write happy multithreaded code with ZeroMQ:
- Isolate data privately within its thread and never share data in multiple threads. The only exception to this are ZeroMQ contexts, which are threadsafe.
- Stay away from the classic concurrency mechanisms like as mutexes, critical sections, semaphores, etc. These are an anti-pattern in ZeroMQ applications.
- Create one ZeroMQ context at the start of your process, and pass that to all threads that you want to connect via inproc sockets.
- Use attached threads to create structure within your application, and connect these to their parent threads using PAIR sockets over inproc. The pattern is: bind parent socket, then create child thread which connects its socket.
- Use detached threads to simulate independent tasks, with their own contexts. Connect these over tcp. Later you can move these to stand-alone processes without changing the code significantly.
- All interaction between threads happens as ZeroMQ messages, which you can define more or less formally.
- Don't share ZeroMQ sockets between threads. ZeroMQ sockets are not threadsafe. Technically it's possible to migrate a socket from one thread to another but it demands skill. The only place where it's remotely sane to share sockets between threads are in language bindings that need to do magic like garbage collection on sockets.引自 Multithreading with ZeroMQ
ZeroMQ uses native OS threads rather than virtual "green" threads. The advantage is that you don't need to learn any new threading API, and that ZeroMQ threads map cleanly to your operating system. You can use standard tools like Intel's ThreadChecker to see what your application is doing.引自 Multithreading with ZeroMQ
There are three main open source development patterns. The first is the large firm dumping code to break the market for others. This is the Apache Foundation model. The second is tiny teams or small firms building their dreams. This is the most common open source model, which can be very successful commercially. The last is aggressive and diverse communities that swarm over a problem landscape....
2013-08-28 13:57:041人喜欢
There are three main open source development patterns. The first is the large firm dumping code to break the market for others. This is the Apache Foundation model. The second is tiny teams or small firms building their dreams. This is the most common open source model, which can be very successful commercially. The last is aggressive and diverse communities that swarm over a problem landscape. This is the Linux model, and the one to which we aspire with ØMQ.引自 The ØMQ Community
- If you start the SUB socket (i.e., establish a connection to a PUB socket) after the PUB socket has started sending out data, you will lose whatever it published before the connection was made. If this is a problem, set up your architecture so the SUB socket starts first, then the PUB socket starts publishing. - Even if you synchronize a SUB and PUB socket, you may still lose messages. It's d...
2016-03-20 14:47:44
- If you start the SUB socket (i.e., establish a connection to a PUB socket) after the PUB socket has started sending out data, you will lose whatever it published before the connection was made. If this is a problem, set up your architecture so the SUB socket starts first, then the PUB socket starts publishing.
- Even if you synchronize a SUB and PUB socket, you may still lose messages. It's due to the fact that internal queues aren't created until a connection is actually created. If you can switch the bind/connect direction so the SUB socket binds, and the PUB socket connects, you may find it works more as you'd expect.引自 Missing Message Problem Solver
如果 SUB socket 的建立在 PUB 发送数据之后,会丢消息。应对:通过某种同步手段先建立 SUB socket 再允许 PUB socket 发送消息;
即使先建立 SUB socket 再建立 PUB socket,依然会丢消息。应对:让 SUB 作服务端来 bind,PUB 作客户端来 connect。
If you're using PUSH sockets, you'll find that the first PULL socket to connect will grab an unfair share of messages.
If you're using inproc, make sure both sockets are in the same context.引自 Missing Message Problem Solver
ZeroMQ uses the concept of HWM (high-water mark) to define the capacity of its internal pipes. Each connection out of a socket or into a socket has its own pipe, and HWM for sending, and/or receiving, depending on the socket type. Some sockets (PUB, PUSH) only have send buffers. Some (SUB, PULL, REQ, REP) only have receive buffers. Some (DEALER, ROUTER, PAIR) have both send and receive buffers....
2016-03-20 14:31:34
ZeroMQ uses the concept of HWM (high-water mark) to define the capacity of its internal pipes. Each connection out of a socket or into a socket has its own pipe, and HWM for sending, and/or receiving, depending on the socket type. Some sockets (PUB, PUSH) only have send buffers. Some (SUB, PULL, REQ, REP) only have receive buffers. Some (DEALER, ROUTER, PAIR) have both send and receive buffers.
In ZeroMQ v2.x, the HWM was infinite by default. This was easy but also typically fatal for high-volume publishers. In ZeroMQ v3.x, it's set to 1,000 by default, which is more sensible
When your socket reaches its HWM, it will either block or drop data depending on the socket type. PUB and ROUTER sockets will drop data if they reach their HWM, while other socket types will block. 引自 High-Water Marks
// Get values that will fool the boss int zipcode, temperature, relhumidity; zipcode = randof (100000); temperature = randof (215) - 80; relhumidity = randof (50) + 10; 注释……lol
2015-09-06 18:34:39
// Get values that will fool the boss
int zipcode, temperature, relhumidity;
zipcode = randof (100000);
temperature = randof (215) - 80;
relhumidity = randof (50) + 10;
Processes, we believe, should be as vulnerable as possible to internal errors, and as robust as possible against external attacks and errors. To give an analogy, a living cell will self-destruct if it detects a single internal error, yet it will resist attack from the outside by all means possible.(4回应)
2013-08-21 12:00:29
Processes, we believe, should be as vulnerable as possible to internal errors, and as robust as possible against external attacks and errors. To give an analogy, a living cell will self-destruct if it detects a single internal error, yet it will resist attack from the outside by all means possible.引自 Handling Errors and ETERM
There are three main open source development patterns. The first is the large firm dumping code to break the market for others. This is the Apache Foundation model. The second is tiny teams or small firms building their dreams. This is the most common open source model, which can be very successful commercially. The last is aggressive and diverse communities that swarm over a problem landscape....
2013-08-28 13:57:041人喜欢
There are three main open source development patterns. The first is the large firm dumping code to break the market for others. This is the Apache Foundation model. The second is tiny teams or small firms building their dreams. This is the most common open source model, which can be very successful commercially. The last is aggressive and diverse communities that swarm over a problem landscape. This is the Linux model, and the one to which we aspire with ØMQ.引自 The ØMQ Community
- If you start the SUB socket (i.e., establish a connection to a PUB socket) after the PUB socket has started sending out data, you will lose whatever it published before the connection was made. If this is a problem, set up your architecture so the SUB socket starts first, then the PUB socket starts publishing. - Even if you synchronize a SUB and PUB socket, you may still lose messages. It's d...
2016-03-20 14:47:44
- If you start the SUB socket (i.e., establish a connection to a PUB socket) after the PUB socket has started sending out data, you will lose whatever it published before the connection was made. If this is a problem, set up your architecture so the SUB socket starts first, then the PUB socket starts publishing.
- Even if you synchronize a SUB and PUB socket, you may still lose messages. It's due to the fact that internal queues aren't created until a connection is actually created. If you can switch the bind/connect direction so the SUB socket binds, and the PUB socket connects, you may find it works more as you'd expect.引自 Missing Message Problem Solver
如果 SUB socket 的建立在 PUB 发送数据之后,会丢消息。应对:通过某种同步手段先建立 SUB socket 再允许 PUB socket 发送消息;
即使先建立 SUB socket 再建立 PUB socket,依然会丢消息。应对:让 SUB 作服务端来 bind,PUB 作客户端来 connect。
If you're using PUSH sockets, you'll find that the first PULL socket to connect will grab an unfair share of messages.
If you're using inproc, make sure both sockets are in the same context.引自 Missing Message Problem Solver
ZeroMQ uses the concept of HWM (high-water mark) to define the capacity of its internal pipes. Each connection out of a socket or into a socket has its own pipe, and HWM for sending, and/or receiving, depending on the socket type. Some sockets (PUB, PUSH) only have send buffers. Some (SUB, PULL, REQ, REP) only have receive buffers. Some (DEALER, ROUTER, PAIR) have both send and receive buffers....
2016-03-20 14:31:34
ZeroMQ uses the concept of HWM (high-water mark) to define the capacity of its internal pipes. Each connection out of a socket or into a socket has its own pipe, and HWM for sending, and/or receiving, depending on the socket type. Some sockets (PUB, PUSH) only have send buffers. Some (SUB, PULL, REQ, REP) only have receive buffers. Some (DEALER, ROUTER, PAIR) have both send and receive buffers.
In ZeroMQ v2.x, the HWM was infinite by default. This was easy but also typically fatal for high-volume publishers. In ZeroMQ v3.x, it's set to 1,000 by default, which is more sensible
When your socket reaches its HWM, it will either block or drop data depending on the socket type. PUB and ROUTER sockets will drop data if they reach their HWM, while other socket types will block. 引自 High-Water Marks
You should think about using zero-copy in the specific case where you are sending large blocks of memory (thousands of bytes), at a high frequency. For short messages, or for lower message rates, using zero-copy will make your code messier and more complex with no measurable benefit. Like all optimizations, use this when you know it helps, and measure before and after.
2016-03-20 12:54:41
You should think about using zero-copy in the specific case where you are sending large blocks of memory (thousands of bytes), at a high frequency. For short messages, or for lower message rates, using zero-copy will make your code messier and more complex with no measurable benefit. Like all optimizations, use this when you know it helps, and measure before and after.
引自 Zero-copy
If there's one lesson we've learned from 30+ years of concurrent programming, it is: just don't share state. You should follow some rules to write happy multithreaded code with ZeroMQ: - Isolate data privately within its thread and never share data in multiple threads. The only exception to this are ZeroMQ contexts, which are threadsafe. - Stay away from the classic concurrency mechanisms like ...
2016-03-19 23:03:56
If there's one lesson we've learned from 30+ years of concurrent programming, it is: just don't share state.
You should follow some rules to write happy multithreaded code with ZeroMQ:
- Isolate data privately within its thread and never share data in multiple threads. The only exception to this are ZeroMQ contexts, which are threadsafe.
- Stay away from the classic concurrency mechanisms like as mutexes, critical sections, semaphores, etc. These are an anti-pattern in ZeroMQ applications.
- Create one ZeroMQ context at the start of your process, and pass that to all threads that you want to connect via inproc sockets.
- Use attached threads to create structure within your application, and connect these to their parent threads using PAIR sockets over inproc. The pattern is: bind parent socket, then create child thread which connects its socket.
- Use detached threads to simulate independent tasks, with their own contexts. Connect these over tcp. Later you can move these to stand-alone processes without changing the code significantly.
- All interaction between threads happens as ZeroMQ messages, which you can define more or less formally.
- Don't share ZeroMQ sockets between threads. ZeroMQ sockets are not threadsafe. Technically it's possible to migrate a socket from one thread to another but it demands skill. The only place where it's remotely sane to share sockets between threads are in language bindings that need to do magic like garbage collection on sockets.引自 Multithreading with ZeroMQ
ZeroMQ uses native OS threads rather than virtual "green" threads. The advantage is that you don't need to learn any new threading API, and that ZeroMQ threads map cleanly to your operating system. You can use standard tools like Intel's ThreadChecker to see what your application is doing.引自 Multithreading with ZeroMQ
1 有用 AlexanderYao 2018-11-20 23:00:21
只读过一小部分,还是没吃透。效率足够高,工作中要用到
0 有用 kiven 2016-11-28 20:46:32
除了最后一章,其他的都看完了, 感觉ZeroMQ很强大。 本来打算在C++中用的,结果现在转做GO了, 现在没有迫切的使用需求了。
0 有用 凝霜 2014-04-04 10:20:37
半年前读的了,里面讲解的很细,讲解了很多实现原理,同时给出了核心代码,非常适合ZMQ的学习
0 有用 江南白衣 2013-08-05 09:02:46
其实就是Guide
0 有用 城北大洋桃有毛 2013-11-05 00:15:56
这货真快
1 有用 [已软注销] 2019-07-12 10:02:48
重读第二遍
0 有用 豆友1094556 2019-06-13 08:19:53
能砍一半
1 有用 AlexanderYao 2018-11-20 23:00:21
只读过一小部分,还是没吃透。效率足够高,工作中要用到
0 有用 中颈鹿 2018-05-12 02:33:08
蛮厉害的
0 有用 kiven 2016-11-28 20:46:32
除了最后一章,其他的都看完了, 感觉ZeroMQ很强大。 本来打算在C++中用的,结果现在转做GO了, 现在没有迫切的使用需求了。