Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame^] | 1 | PSync examples |
| 2 | ============== |
| 3 | |
| 4 | By default, examples in `examples/` folder are not built. To enable them, use |
| 5 | `--with-examples` configure option. For example: |
| 6 | |
| 7 | ./waf configure --with-examples |
| 8 | ./waf |
| 9 | |
| 10 | Example binary can be found under `build/examples`: |
| 11 | |
| 12 | - Full sync : `psync-full-sync` |
| 13 | - Partial sync : `psync-producer` and `psync-consumer` |
| 14 | |
| 15 | If the library is installed to the system using `./waf install` then the examples |
| 16 | are also installed and can be executed directly. |
| 17 | |
| 18 | ## Partial Sync Example |
| 19 | |
| 20 | Partial sync example of PSync has two parts: producer and consumer. |
| 21 | These can be run on a machine after starting NFD: |
| 22 | |
| 23 | ### Producer |
| 24 | |
| 25 | - Enable the logs for producer: |
| 26 | |
| 27 | ```bash |
| 28 | export NDN_LOG=examples.PartialSyncProducerApp=INFO |
| 29 | ``` |
| 30 | |
| 31 | - Start the producer that will listen on /sync and publish 1 update for /a-0 ... /a-9 each. |
| 32 | |
| 33 | ```bash |
| 34 | psync-producer /sync /a 10 1 |
| 35 | ``` |
| 36 | |
| 37 | - Sample output: |
| 38 | |
| 39 | ``` |
| 40 | 1546280442.096296 INFO: [examples.PartialSyncProducerApp] Publish: /a-1/1 |
| 41 | 1546280456.053138 INFO: [examples.PartialSyncProducerApp] Publish: /a-6/1 |
| 42 | 1546280458.210415 INFO: [examples.PartialSyncProducerApp] Publish: /a-8/1 |
| 43 | 1546280469.954134 INFO: [examples.PartialSyncProducerApp] Publish: /a-5/1 |
| 44 | 1546280472.487425 INFO: [examples.PartialSyncProducerApp] Publish: /a-2/1 |
| 45 | 1546280473.466515 INFO: [examples.PartialSyncProducerApp] Publish: /a-7/1 |
| 46 | 1546280481.882258 INFO: [examples.PartialSyncProducerApp] Publish: /a-0/1 |
| 47 | 1546280484.201229 INFO: [examples.PartialSyncProducerApp] Publish: /a-4/1 |
| 48 | 1546280489.348968 INFO: [examples.PartialSyncProducerApp] Publish: /a-9/1 |
| 49 | 1546280491.420391 INFO: [examples.PartialSyncProducerApp] Publish: /a-3/1 |
| 50 | ``` |
| 51 | |
| 52 | ### Consumer |
| 53 | |
| 54 | - In a new terminal, enable the logs for consumer: |
| 55 | |
| 56 | ```bash |
| 57 | export NDN_LOG=examples.PartialSyncConsumerApp=INFO |
| 58 | ``` |
| 59 | |
| 60 | - Run the consumer to subscribe to 5 random prefixes from the publisher on /sync |
| 61 | |
| 62 | ```bash |
| 63 | psync-consumer /sync 5 |
| 64 | ``` |
| 65 | |
| 66 | - Sample output from the consumer shows that it received updates only |
| 67 | for the subscribed prefixes: |
| 68 | |
| 69 | ``` |
| 70 | 1546280436.502769 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-7 |
| 71 | 1546280436.502888 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-9 |
| 72 | 1546280436.502911 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-8 |
| 73 | 1546280436.502934 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-4 |
| 74 | 1546280436.502956 INFO: [examples.PartialSyncConsumerApp] Subscribing to: /a-5 |
| 75 | 1546280458.211188 INFO: [examples.PartialSyncConsumerApp] Update: /a-8/1 |
| 76 | 1546280469.954886 INFO: [examples.PartialSyncConsumerApp] Update: /a-5/1 |
| 77 | 1546280473.467116 INFO: [examples.PartialSyncConsumerApp] Update: /a-7/1 |
| 78 | 1546280484.256181 INFO: [examples.PartialSyncConsumerApp] Update: /a-4/1 |
| 79 | 1546280489.349793 INFO: [examples.PartialSyncConsumerApp] Update: /a-9/1 |
| 80 | ``` |
| 81 | |
| 82 | ## Full Sync Example |
| 83 | |
| 84 | To demonstrate full sync mode of PSync, ``psync-full-sync`` |
| 85 | can be run on a machine after starting NFD: |
| 86 | |
| 87 | - Enable the logs for full sync: |
| 88 | |
| 89 | ```bash |
| 90 | export NDN_LOG=examples.FullSyncApp=INFO |
| 91 | ``` |
| 92 | |
| 93 | - Run the full sync example with sync prefix /sync, user prefix /a, |
| 94 | and publish three updates for each user prefix: /a-0 and /a-1. This will simulate node a. |
| 95 | |
| 96 | ```bash |
| 97 | psync-full-sync /sync /a 2 3 |
| 98 | ``` |
| 99 | |
| 100 | - Repeat for another user prefix, to simulate node b: |
| 101 | |
| 102 | ```bash |
| 103 | psync-full-sync /sync /b 2 3 |
| 104 | ``` |
| 105 | |
| 106 | We should see that node a and node b have received each other's updates. |
| 107 | |
| 108 | - Sample output from node a shows that it received all updates |
| 109 | from node b successfully: |
| 110 | |
| 111 | ``` |
| 112 | 1546282730.759387 INFO: [examples.FullSyncApp] Update /b-1/1 |
| 113 | 1546282741.143225 INFO: [examples.FullSyncApp] Publish: /a-1/1 |
| 114 | 1546282749.375854 INFO: [examples.FullSyncApp] Publish: /a-0/1 |
| 115 | 1546282750.263246 INFO: [examples.FullSyncApp] Update /b-0/1 |
| 116 | 1546282765.875118 INFO: [examples.FullSyncApp] Update /b-1/2 |
| 117 | 1546282783.777807 INFO: [examples.FullSyncApp] Publish: /a-0/2 |
| 118 | 1546282794.565507 INFO: [examples.FullSyncApp] Publish: /a-0/3 |
| 119 | 1546282794.896895 INFO: [examples.FullSyncApp] Publish: /a-1/2 |
| 120 | 1546282803.839416 INFO: [examples.FullSyncApp] Update /b-0/2 |
| 121 | 1546282804.785867 INFO: [examples.FullSyncApp] Update /b-1/3 |
| 122 | 1546282845.273772 INFO: [examples.FullSyncApp] Publish: /a-1/3 |
| 123 | 1546282855.102790 INFO: [examples.FullSyncApp] Update /b-0/3 |
| 124 | ``` |
| 125 | |
| 126 | - Sample output from node b: |
| 127 | |
| 128 | ``` |
| 129 | 1546282730.758296 INFO: [examples.FullSyncApp] Publish: /b-1/1 |
| 130 | 1546282741.144027 INFO: [examples.FullSyncApp] Update /a-1/1 |
| 131 | 1546282749.376543 INFO: [examples.FullSyncApp] Update /a-0/1 |
| 132 | 1546282750.262244 INFO: [examples.FullSyncApp] Publish: /b-0/1 |
| 133 | 1546282765.296005 INFO: [examples.FullSyncApp] Publish: /b-1/2 |
| 134 | 1546282783.778769 INFO: [examples.FullSyncApp] Update /a-0/2 |
| 135 | 1546282794.566485 INFO: [examples.FullSyncApp] Update /a-0/3 |
| 136 | 1546282795.374339 INFO: [examples.FullSyncApp] Update /a-1/2 |
| 137 | 1546282803.838394 INFO: [examples.FullSyncApp] Publish: /b-0/2 |
| 138 | 1546282804.033214 INFO: [examples.FullSyncApp] Publish: /b-1/3 |
| 139 | 1546282845.274680 INFO: [examples.FullSyncApp] Update /a-1/3 |
| 140 | 1546282855.101780 INFO: [examples.FullSyncApp] Publish: /b-0/3 |
| 141 | ``` |