David Blume commited on 2019-07-05 20:33:19
Showing 1 changed files, with 19 additions and 8 deletions.
... | ... |
@@ -8,7 +8,9 @@ repeatedly ping multiple hosts to see if the network is up. |
8 | 8 |
This is the most naive implementation. For each ping host, the main |
9 | 9 |
process thread pings them one at a time, and prints any changes. |
10 | 10 |
|
11 |
-![Single Threaded Pings](http://git.dlma.com/python_pinger.git/blob/master/images/ping_single_threaded.png) |
|
11 |
+![Single Threaded Pings](http://dlma.com/images/python_pinger/ping_single_threaded.png) |
|
12 |
+ |
|
13 |
+It's so simple that I'm not going to provide a sample source file, but for the others below, I will. |
|
12 | 14 |
|
13 | 15 |
### Upsides |
14 | 16 |
|
... | ... |
@@ -24,9 +26,9 @@ affect detecting a problem at another host. |
24 | 26 |
Raymond Hettinger's [PyBay 2018 Keynote](https://pybay.com/site_media/slides/raymond2017-keynote/threading.html) |
25 | 27 |
uses the queue module to send data between threads, so I thought I'd make a version of the pinger that did the same. |
26 | 28 |
|
27 |
-[long\_lived\_worker\_queue.py](http://git.dlma.com/python_pinger.git/blob/master/long_lived_worker_queue.py) |
|
29 |
+![Long Lived Queue Workers](http://dlma.com/images/python_pinger/ping_long_lived_queue_workers.png) |
|
28 | 30 |
|
29 |
-![Long Lived Queue Workers](http://git.dlma.com/python_pinger.git/blob/master/images/ping_long_lived_queue_workers.png) |
|
31 |
+See the source: **[long\_lived\_worker\_queue.py](http://git.dlma.com/python_pinger.git/blob/master/long_lived_worker_queue.py)** |
|
30 | 32 |
|
31 | 33 |
### Upsides |
32 | 34 |
|
... | ... |
@@ -34,13 +36,18 @@ Multi-threaded ping calls won't block each other. |
34 | 36 |
|
35 | 37 |
### Downsides |
36 | 38 |
|
37 |
-The ping tasks read from, and write to a shared dictionary. (Reading and updating the last status.) |
|
39 |
+The ping tasks read from, and write to a shared dictionary. (Reading and |
|
40 |
+updating the last status.) |
|
38 | 41 |
|
39 | 42 |
## Short Lived Workers |
40 | 43 |
|
41 |
-![Short Lived Workers](http://git.dlma.com/python_pinger.git/blob/master/images/ping_short_lived_workers.png) |
|
44 |
+How about we don't keep the workers around, and only spawn them when |
|
45 |
+there's something to do? That way, we won't waste memory when there's |
|
46 |
+nothing going on. |
|
47 |
+ |
|
48 |
+![Short Lived Workers](http://dlma.com/images/python_pinger/ping_short_lived_workers.png) |
|
42 | 49 |
|
43 |
-[short\_lived\_workers.py](http://git.dlma.com/python_pinger.git/blob/master/short_lived_workers.py) |
|
50 |
+See the source: **[short\_lived\_workers.py](http://git.dlma.com/python_pinger.git/blob/master/short_lived_workers.py)** |
|
44 | 51 |
|
45 | 52 |
### Upsides |
46 | 53 |
|
... | ... |
@@ -52,9 +59,13 @@ The ping tasks still read from, and write to a shared dictionary. (Reading and u |
52 | 59 |
|
53 | 60 |
## Long Lived Looping Workers |
54 | 61 |
|
55 |
-![Long Lived Looping Workers](http://git.dlma.com/python_pinger.git/blob/master/images/ping_long_lived_looping_workers.png) |
|
62 |
+I saved the best for last. The only thing the main thread does is bring the |
|
63 |
+workers and the print manager to life. The workers each independently do their own loop: |
|
64 |
+ping, compare, print, and wait. |
|
65 |
+ |
|
66 |
+![Long Lived Looping Workers](http://dlma.com/images/python_pinger/ping_long_lived_looping_workers.png) |
|
56 | 67 |
|
57 |
-[long\_lived\_looping\_workers.py](http://git.dlma.com/python_pinger.git/blob/master/long_lived_looping_workers.py) |
|
68 |
+See the source: **[long\_lived\_looping\_workers.py](http://git.dlma.com/python_pinger.git/blob/master/long_lived_looping_workers.py)** |
|
58 | 69 |
|
59 | 70 |
### Upsides |
60 | 71 |
|
61 | 72 |