diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | cmd/dexcon-simulation-with-scheduler/main.go | 9 | ||||
-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 |
8 files changed, 102 insertions, 7 deletions
@@ -66,8 +66,8 @@ dexcon-simulation -config test.toml -init make ``` -3. Run simulation with 10 workers: +3. Run simulation with scheduler: ``` -dexcon-simulation-with-scheduler -config test.toml -workercount 10 +dexcon-simulation-with-scheduler -config test.toml ``` diff --git a/cmd/dexcon-simulation-with-scheduler/main.go b/cmd/dexcon-simulation-with-scheduler/main.go index 3ed71c3..b9f5ec3 100644 --- a/cmd/dexcon-simulation-with-scheduler/main.go +++ b/cmd/dexcon-simulation-with-scheduler/main.go @@ -16,10 +16,9 @@ import ( ) var ( - configFile = flag.String("config", "", "path to simulation config file") - cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`") - memprofile = flag.String("memprofile", "", "write memory profile to `file`") - workerCount = flag.Int("workercount", 1, "count of concurrent workers") + configFile = flag.String("config", "", "path to simulation config file") + cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`") + memprofile = flag.String("memprofile", "", "write memory profile to `file`") ) func main() { @@ -72,7 +71,7 @@ func main() { } } // Run the simulation. - sch.Run(*workerCount) + sch.Run(cfg.Scheduler.WorkerNum) if err = integration.VerifyApps(apps); err != nil { log.Fatal("consensus result is not incorrect: ", err) } 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" |