Permalink
Browse files

Working on pirate patterns

  • Loading branch information...
1 parent 4f41571 commit d4af6b07056a49a6e675e3a00320b01cb79cd151 @hintjens hintjens committed Feb 27, 2011
View
@@ -234,10 +234,10 @@ We'll make an example where the dealers don't talk back, they're pure sinks. Our
[[code type="textdiagram"]]
+-------------+
| |
- | Client | Send to "A" or "B"
+ | Client | Send to "A" or "B"
| |
+-------------+
- | ROUTER |
+ | XREP | (ROUTER)
\------+------/
|
|
@@ -246,7 +246,7 @@ We'll make an example where the dealers don't talk back, they're pure sinks. Our
| |
v v
/-----------\ /-----------\
- | DEALER | | DEALER |
+ | XREQ | | XREQ | (DEALER)
| "A" | | "B" |
+-----------+ +-----------+
| | | |
@@ -307,7 +307,7 @@ Like dealers, mamas can only talk to one router and since mamas always start by
| Client | Send to "A" or "B"
| |
+-------------+
- | ROUTER | OK, it's really XREP
+ | XREP | (ROUTER)
\-------------/
^
| (1) Mama says Hi
@@ -317,7 +317,7 @@ Like dealers, mamas can only talk to one router and since mamas always start by
| | (2) Router gives laundry
v v
/-----------\ /-----------\
- | MAMA | | MAMA | Aka. REQ
+ | REQ | | REQ | (MAMA)
| "A" | | "B" |
+-----------+ +-----------+
| | | |
@@ -399,7 +399,7 @@ A core philosophy of 0MQ is that the edges are smart and many, and the middle is
| Client | Send to "A" or "B"
| |
+-------------+
- | ROUTER | Yes, it's still XREP
+ | XREP | (ROUTER)
\-------------/
^
|
@@ -409,7 +409,7 @@ A core philosophy of 0MQ is that the edges are smart and many, and the middle is
| |
v v
/-----------\ /-----------\
- | PAPA | | PAPA | REP, naturally
+ | REP | | REP | (PAPA)
| "A" | | "B" |
+-----------+ +-----------+
| | | |
@@ -486,15 +486,15 @@ To start with, let's look back at the classic request-reply pattern and then see
+--------+
| Client |
+--------+
- | Mama | REQ
- +---+----+ ^
- | |
- | |
- +-----------+-----------+ |
- | | | |
- | | | |
-+---+----+ +---+----+ +---+----+ v
-| Papa | | Papa | | Papa | REP
+ | REQ | (MAMA)
+ +---+----+
+ |
+ |
+ +-----------+-----------+
+ | | |
+ | | |
++---+----+ +---+----+ +---+----+
+| REP | | REP | | REP | (PAPA)
+--------+ +--------+ +--------+
| Worker | | Worker | | Worker |
+--------+ +--------+ +--------+
@@ -509,23 +509,23 @@ This extends to multiple papas, but if we want to handle multiple mamas as well
+--------+ +--------+ +--------+
| Client | | Client | | Client |
+--------+ +--------+ +--------+
-| Mama | | Mama | | Mama | REQ
+| REQ | | REQ | | REQ | MAMA
+---+----+ +---+----+ +---+----+ ^
| | | |
+-----------+-----------+ |
| |
+---+----+ v
- | Router | XREP
+ | XREP | ROUTER
+--------+ :
| Device | :
+--------+ :
- | Dealer | XREQ
+ | XREQ | DEALER
+---+----+ ^
| |
+-----------+-----------+ |
| | | |
+---+----+ +---+----+ +---+----+ v
-| Papa | | Papa | | Papa | REP
+| REP | | REP | | REP | PAPA
+--------+ +--------+ +--------+
| Worker | | Worker | | Worker |
+--------+ +--------+ +--------+
@@ -542,23 +542,23 @@ In the above design, we're using the built-in load balancing routing that the de
+--------+ +--------+ +--------+
| Client | | Client | | Client |
+--------+ +--------+ +--------+
- | Mama | | Mama | | Mama | REQ
+ | REQ | | REQ | | REQ | MAMA
+---+----+ +---+----+ +---+----+ ^
| | | |
+-----------+-----------+ |
| |
+---+----+ v
- | Router | Frontend XREP
+ | XREP | Frontend ROUTER
+--------+ :
| Device | LRU queue :
+--------+ :
- | Router | Backend XREP
+ | XREP | Backend ROUTER
+---+----+ ^
| |
+-----------+-----------+ |
| | | |
+---+----+ +---+----+ +---+----+ v
- | Mama | | Mama | | Mama | REQ
+ | REQ | | REQ | | REQ | MAMA
+--------+ +--------+ +--------+
| Worker | | Worker | | Worker |
+--------+ +--------+ +--------+
@@ -774,7 +774,7 @@ In the router-to-dealer example we saw a 1-to-N use case where one client talks
| Client | | Client |
| | | |
+-----------+ +-----------+
- | DEALER | | DEALER |
+ | XREQ | | XREQ | (DEALER)
\-----------/ \-----------/
^ ^
| |
@@ -784,7 +784,7 @@ In the router-to-dealer example we saw a 1-to-N use case where one client talks
|
v
/------+------\
- | ROUTER |
+ | XREP | (ROUTER)
+-------------+
| |
| Server |
@@ -846,7 +846,7 @@ The socket logic in the server is fairly wicked. This is the detailed architectu
: | :
: +-------------+-------------+ :
: | | | :
- : v v v :
+ : v v v :
: connect connect connect :
: /---------\ /---------\ /---------\ :
: | XREQ | | XREQ | | XREQ | :
@@ -857,7 +857,7 @@ The socket logic in the server is fairly wicked. This is the detailed architectu
: +---------+ +---------+ +---------+ :
: :
\---------------------------------------------/
-
+
Figure # - Detail of async server
[[/code]]
@@ -879,11 +879,11 @@ The second design is much simpler, so that's what we use:
When you build servers that maintain stateful conversations with clients, you will run into a classic problem. If the server keeps some state per client, and clients keep coming and going, eventually it will run of resources. Even if the same clients keep connecting, if you're using transient sockets (no explicit identity), each connection will look like a new one.
-We cheat in the above example by keeping state only for a very short time (the time it takes a worker to process a request) and then throwing away the state. But that's not practical for many cases.
+We cheat in the above example by keeping state only for a very short time (the time it takes a worker to process a request) and then throwing away the state. But that's not practical for many cases.
To properly manage client state in a stateful asynchronous server you must:
-* Do heartbeating from client to server. In our example we send a request once per second, which can reliably be used as a heartbeat.
+* Do heartbeating from client to server. In our example we send a request once per second, which can reliably be used as a heartbeat.
* Store state using the client identity as key. This works for both durable and transient sockets.
* Detect a stopped heartbeat. If there's no request from a client within, say, two seconds, the server can detect this and destroy any state it's holding for that client.
@@ -898,7 +898,7 @@ We've seen XREP/router sockets talking to dealers, mamas, and papas. The last ca
| Front-end | | Front-end |
| | | |
+-----------+ +-----------+
- | Router | | Router | XREP
+ | XREP | | XREP | ROUTER
\-----------/ \-----------/ ^
connect connect |
^ ^ |
@@ -911,7 +911,7 @@ We've seen XREP/router sockets talking to dealers, mamas, and papas. The last ca
v v |
bind bind |
/-----------\ /-----------\ v
- | Router | | Router | XREP
+ | XREP | | XREP | ROUTER
+-----------+ +-----------+
| | | |
| Worker | | Worker |
@@ -996,19 +996,19 @@ For reasons we already looked at, clients and workers won't speak to each other
+--------+ +--------+ +--------+
| Client | | Client | | Client |
+--------+ +--------+ +--------+
- | Mama | | Mama | | Mama | REQ
+ | REQ | | REQ | | REQ | (MAMA)
+---+----+ +---+----+ +---+----+
| | |
+-----------+-----------+
|
+--------------------------------+
| | |
| +-----+------+ |
- | | Router | | XREP
+ | | XREP | | (ROUTER)
| +------------+ |
| | LRU Queue | |
| +------------+ |
- | | Router | | XREP
+ | | XREP | | (ROUTER)
| +-----+------+ |
| | Broker :
+--------------------------------+
@@ -1017,7 +1017,7 @@ For reasons we already looked at, clients and workers won't speak to each other
+-----------+-----------+
| | |
+---+----+ +---+----+ +---+----+
- | Mama | | Mama | | Mama | REQ
+ | REQ | | REQ | | REQ | (MAMA)
+--------+ +--------+ +--------+
| Worker | | Worker | | Worker |
+--------+ +--------+ +--------+
@@ -1070,7 +1070,7 @@ Let's explore Idea #1. Workers connecting to both brokers and accepting jobs fro
:
| | | |
+------------+ +------------+
- | Router | | Router |
+ | XREP | | XREP |
+-----+------+ +-----+------+
| |
+---------|-+--=--------+--------------+
@@ -1079,7 +1079,7 @@ Let's explore Idea #1. Workers connecting to both brokers and accepting jobs fro
| : | : | :
| : | : | :
+---+-+--+ +---+-+--+ +---+-+--+
- | Router | | Router | | Router |
+ | XREP | | XREP | | XREP |
+--------+ +--------+ +--------+
| Worker | | Worker | | Worker |
+--------+ +--------+ +--------+
Oops, something went wrong.

0 comments on commit d4af6b0

Please sign in to comment.