Skip to content

Instantly share code, notes, and snippets.

@minhnhdo
Last active March 1, 2018 21:02
Show Gist options
  • Save minhnhdo/f490424784111f9396bbf33b37f4e8b2 to your computer and use it in GitHub Desktop.
Save minhnhdo/f490424784111f9396bbf33b37f4e8b2 to your computer and use it in GitHub Desktop.
version: '2'
services:
etcd1:
image: quay.io/coreos/etcd
container_name: etcd1
command: >
etcd -name etcd1
-advertise-client-urls http://172.28.128.7:2379,http://172.28.128.7:4001
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
-initial-advertise-peer-urls http://172.28.128.7:2380
-listen-peer-urls http://0.0.0.0:2380
-initial-cluster-token etcd-cluster-1
-initial-cluster etcd1=http://172.28.128.7:2380,etcd2=http://172.28.128.8:2380,etcd3=http://172.28.128.9:2380
-initial-cluster-state new
networks:
etcd:
ipv4_address: 172.28.128.7
etcd2:
image: quay.io/coreos/etcd
container_name: etcd2
command: >
etcd -name etcd2
-advertise-client-urls http://172.28.128.8:2379,http://172.28.128.8:4001
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
-initial-advertise-peer-urls http://172.28.128.8:2380
-listen-peer-urls http://0.0.0.0:2380
-initial-cluster-token etcd-cluster-1
-initial-cluster etcd1=http://172.28.128.7:2380,etcd2=http://172.28.128.8:2380,etcd3=http://172.28.128.9:2380
-initial-cluster-state new
networks:
etcd:
ipv4_address: 172.28.128.8
etcd3:
image: quay.io/coreos/etcd
container_name: etcd3
command: >
etcd -name etcd3
-advertise-client-urls http://172.28.128.9:2379,http://172.28.128.9:4001
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
-initial-advertise-peer-urls http://172.28.128.9:2380
-listen-peer-urls http://0.0.0.0:2380
-initial-cluster-token etcd-cluster-1
-initial-cluster etcd1=http://172.28.128.7:2380,etcd2=http://172.28.128.8:2380,etcd3=http://172.28.128.9:2380
-initial-cluster-state new
networks:
etcd:
ipv4_address: 172.28.128.9
networks:
etcd:
driver: bridge
ipam:
config:
- subnet: 172.28.128.0/28
5a6
> "math/rand"
9a11
> "time"
12a15
> var jobs []string = []string{" generate report", " send email", " dispense sweets", " launch nukes", " rebuild civilization", " seize means of production"}
16a20,22
> globalState.Lock(selfStr, "0")
> globalState.Set("queue", []string{})
> globalState.Unlock(selfStr, "0")
17a24,25
> i := rand.Intn(len(jobs))
> job := jobs[i]
20c28
< globalState.Set("queue", append(globalState.GetStringCollection("queue"), "resource"))
---
> globalState.Set("queue", append(globalState.GetStringCollection("queue"), selfStr+job))
33d40
< fmt.Printf("%v\n", (resource))
35a43,45
> t := rand.Intn(1000)
> time.Sleep(time.Duration(t) * time.Millisecond)
> fmt.Printf("%s[%03dms] %v\n", selfStr, t, resource)
39a50
> rand.Seed(time.Now().UnixNano())
#! /bin/sh
usage() {
echo "$0 [<binary> <number-of-producers> <number-of-consumers>]"
exit 1
}
BIN=${1:-./gen/gen}
NPROC=${2:-1}
NCONS=${3:-2}
echo "Clear previous run"
killall $BIN
docker exec -ti etcd1 etcdctl rm /locks/0
docker exec -ti etcd1 etcdctl rm /queue
for i in `seq $NPROC`; do
echo "Starting Producer($i)"
$BIN "Producer($i)" >logs/producer-$i.log 2>&1 &
done
sleep 1
for i in `seq $NCONS`; do
echo "Starting Consumer($i)"
$BIN "Consumer($i)" >logs/consumer-$i.log 2>&1 &
done
watch -n 0.1 'tail -n 5 logs/*.log'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment