diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-08-22 14:00:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-22 14:00:04 +0800 |
commit | 2f7bb14d1d4b1e11129109d3ec2386d004ffb8af (patch) | |
tree | 8dcf16f18852023fc668b7a2d41be9192c2b19e7 /simulation | |
parent | 89a65a152ae7956bcf6d241eb15d66e6d955b819 (diff) | |
download | dexon-consensus-2f7bb14d1d4b1e11129109d3ec2386d004ffb8af.tar dexon-consensus-2f7bb14d1d4b1e11129109d3ec2386d004ffb8af.tar.gz dexon-consensus-2f7bb14d1d4b1e11129109d3ec2386d004ffb8af.tar.bz2 dexon-consensus-2f7bb14d1d4b1e11129109d3ec2386d004ffb8af.tar.lz dexon-consensus-2f7bb14d1d4b1e11129109d3ec2386d004ffb8af.tar.xz dexon-consensus-2f7bb14d1d4b1e11129109d3ec2386d004ffb8af.tar.zst dexon-consensus-2f7bb14d1d4b1e11129109d3ec2386d004ffb8af.zip |
simulation: allow to run simulation with scheduler on k8s (#72)
To run a simulation with scheduler on k8s:
./run_scheduler.sh 61 5
Where *61* means the simulation contains 61 validators, and *5* means
the simulation utilizes 5 vCPUs and corresponding concurrent workers to run.
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/config/config.go | 9 | ||||
-rw-r--r-- | simulation/kubernetes/Dockerfile | 1 | ||||
-rw-r--r-- | simulation/kubernetes/config.toml.in | 3 | ||||
-rwxr-xr-x | simulation/kubernetes/entrypoint.sh | 2 | ||||
-rwxr-xr-x | simulation/kubernetes/run_scheduler.sh | 44 | ||||
-rw-r--r-- | simulation/kubernetes/scheduler.yaml.in | 37 |
6 files changed, 96 insertions, 0 deletions
diff --git a/simulation/config/config.go b/simulation/config/config.go index cb67411..fe91881 100644 --- a/simulation/config/config.go +++ b/simulation/config/config.go @@ -59,11 +59,17 @@ type Networking struct { LossRateValue float64 } +// Scheduler Settings. +type Scheduler struct { + WorkerNum int +} + // Config represents the configuration for simulation. type Config struct { Title string Validator Validator Networking Networking + Scheduler Scheduler } // GenerateDefault generates a default configuration file. @@ -93,6 +99,9 @@ func GenerateDefault(path string) error { Sigma: 10, LossRateValue: 0, }, + Scheduler: Scheduler{ + WorkerNum: 2, + }, } if err := toml.NewEncoder(f).Encode(&config); err != nil { diff --git a/simulation/kubernetes/Dockerfile b/simulation/kubernetes/Dockerfile index c6599d8..3a30ebd 100644 --- a/simulation/kubernetes/Dockerfile +++ b/simulation/kubernetes/Dockerfile @@ -7,6 +7,7 @@ RUN mkdir -p /opt/dexon/ # Copy data. COPY build/dexcon-simulation /opt/dexon COPY build/dexcon-simulation-peer-server /opt/dexon +COPY build/dexcon-simulation-with-scheduler /opt/dexon COPY entrypoint.sh /opt/dexon COPY config.toml /opt/dexon diff --git a/simulation/kubernetes/config.toml.in b/simulation/kubernetes/config.toml.in index 4e4ec0b..79e662a 100644 --- a/simulation/kubernetes/config.toml.in +++ b/simulation/kubernetes/config.toml.in @@ -16,3 +16,6 @@ peer_server = "peer-server-svc.default.svc.cluster.local" mean = 1e+02 sigma = 1e+01 loss_rate_value = 0e+00 + +[scheduler] +worker_num = 2 diff --git a/simulation/kubernetes/entrypoint.sh b/simulation/kubernetes/entrypoint.sh index a892580..370b0c2 100755 --- a/simulation/kubernetes/entrypoint.sh +++ b/simulation/kubernetes/entrypoint.sh @@ -4,4 +4,6 @@ if [ "$ROLE" = "validator" ]; then exec ./dexcon-simulation -config config.toml elif [ "$ROLE" = "peer-server" ]; then exec ./dexcon-simulation-peer-server -config config.toml +elif [ "$ROLE" = "scheduler" ]; then + exec ./dexcon-simulation-with-scheduler -config config.toml fi diff --git a/simulation/kubernetes/run_scheduler.sh b/simulation/kubernetes/run_scheduler.sh new file mode 100755 index 0000000..0ebd1a5 --- /dev/null +++ b/simulation/kubernetes/run_scheduler.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +IMAGE_TAG=asia.gcr.io/cobinhood/dexcon-simulation:latest + +build_binary() { + make DOCKER=true -C ../.. + cp -r ../../build . +} + +build_docker_image() { + docker build -t ${IMAGE_TAG} . + docker push ${IMAGE_TAG} +} + +start_simulation() { + kubectl delete deployment dexcon-simulation-with-scheduler --force --grace-period=0 + sleep 30 + + kubectl apply -f scheduler.yaml +} + +main() { + local num_validators=$1 + local num_cpus=$2 + + if [ "$num_validators" == "" ]; then + num_validators=31 + fi + + if [ "$num_cpus" == "" ]; then + num_cpus=2 + fi + + + # Render configuration files. + sed "s/{{numValidators}}/$num_validators/" config.toml.in > config.toml + sed "s/{{numCPUs}}/$num_cpus/" scheduler.yaml.in > scheduler.yaml + + build_binary + build_docker_image + start_simulation +} + +main $* diff --git a/simulation/kubernetes/scheduler.yaml.in b/simulation/kubernetes/scheduler.yaml.in new file mode 100644 index 0000000..0f17a4c --- /dev/null +++ b/simulation/kubernetes/scheduler.yaml.in @@ -0,0 +1,37 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: dexcon-simulation-with-scheduler + labels: + app: dexcon-simulation-with-scheduler +spec: + revisionHistoryLimit: 5 + replicas: 1 + template: + metadata: + name: dexcon-simulation-with-scheduler + labels: + app: dexcon-simulation-with-scheduler + spec: + nodeSelector: + cloud.google.com/gke-nodepool: default-pool + volumes: + - name: ssl-certs + hostPath: + path: /etc/ssh/certs + containers: + - name: dexcon-simulation-with-scheduler + image: asia.gcr.io/cobinhood/dexcon-simulation:latest + imagePullPolicy: Always + ports: + - containerPort: 8080 + resources: + requests: + cpu: {{numCPUs}} + memory: 4Gi + limits: + cpu: {{numCPUs}} + memory: 4Gi + env: + - name: ROLE + value: "scheduler" |