Skip to content

Commit

Permalink
Problem: no cluster benchmarking
Browse files Browse the repository at this point in the history
Integrate testground to do network benchmarking
  • Loading branch information
yihuang committed May 9, 2024
1 parent 5ba9b8c commit 9ad2ad7
Show file tree
Hide file tree
Showing 6 changed files with 710 additions and 0 deletions.
62 changes: 62 additions & 0 deletions testground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Guide

[Testground documentation](https://docs.testground.ai/)

## Getting started

### Prerequisites

- docker
- go 1.22, or higher

### Install Testground

```bash
$ git clone https://github.com/testground/testground.git
$ cd testground
# compile Testground and all related dependencies
$ make install
```

It'll install the `testground` binary in your `$GOPATH/bin` directory, and build several docker images.

### Running Testground

```bash
$ TESTGROUND_HOME=$PWD/data testground daemon
```

Keep the daemon process running during the test.

### Running Test Plan

Import the test plan before the first run:

```bash
$ TESTGROUND_HOME=$PWD/data testground plan import --from /path/to/cronos/testground/benchmark
```

Run the benchmark test plan locally:

```
$ testground run single --plan=benchmark --instances=2 --testcase=entrypoint --builder=docker:generic --runner=local:docker --wait
```

### macOS

If you use `colima` as docker runtime on macOS, create the symbolic link `/var/run/docker.sock`:

```bash
$ sudo ln -s /Users/huangyi/.colima/docker.sock /var/run/docker.sock
```

And mount the directories into the virtual machine:

```toml
mounts:
- location: /var/folders
writable: false
- location: <TESTGROUND_HOME>
writable: true
```

89 changes: 89 additions & 0 deletions testground/benchmark/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# BUILD_BASE_IMAGE is the base image to use for the build. It contains a rolling
# accumulation of Go build/package caches.
ARG BUILD_BASE_IMAGE=docker.io/golang:1.22.0-alpine3.18
# This Dockerfile performs a multi-stage build and RUNTIME_IMAGE is the image
# onto which to copy the resulting binary.
#
# Picking a different runtime base image from the build image allows us to
# slim down the deployable considerably.
#
# The user can override the runtime image by passing in the appropriate builder
# configuration option.
ARG RUNTIME_IMAGE=alpine:3.18

#:::
#::: BUILD CONTAINER
#:::
FROM ${BUILD_BASE_IMAGE} AS builder

# PLAN_DIR is the location containing the plan source inside the container.
ENV PLAN_DIR /plan

ENV INFLUXDB_URL=http://influxdb:8086

# SDK_DIR is the location containing the (optional) sdk source inside the container.
ENV SDK_DIR /sdk

# Delete any prior artifacts, if this is a cached image.
RUN rm -rf ${PLAN_DIR} ${SDK_DIR} /testground_dep_lists

# TESTPLAN_EXEC_PKG is the executable package of the testplan to build.
# The image will build that package only.
ARG TESTPLAN_EXEC_PKG="."

# GO_PROXY is the go proxy that will be used, or direct by default.
ARG GO_PROXY=https://proxy.golang.org

# BUILD_TAGS is either nothing, or when expanded, it expands to "-tags <comma-separated build tags>"
ARG BUILD_TAGS

# TESTPLAN_EXEC_PKG is the executable package within this test plan we want to build.
ENV TESTPLAN_EXEC_PKG ${TESTPLAN_EXEC_PKG}

# We explicitly set GOCACHE under the /go directory for more tidiness.
ENV GOCACHE /go/cache


# Copy only go.mod files and download deps, in order to leverage Docker caching.
COPY /plan/go.mod ${PLAN_DIR}/go.mod

RUN apk add gcompat

# Download deps.
RUN echo "Using go proxy: ${GO_PROXY}" \
&& cd ${PLAN_DIR} \
&& go env -w GOPROXY="${GO_PROXY}" \
&& go mod download


# Now copy the rest of the source and run the build.
COPY . /


RUN cd ${PLAN_DIR} \
&& go env -w GOPROXY="${GO_PROXY}" \
&& CGO_ENABLED=${CgoEnabled} GOOS=linux GOARCH=amd64 go build -o ${PLAN_DIR}/testplan.bin ${BUILD_TAGS} ${TESTPLAN_EXEC_PKG}

# Store module dependencies
RUN cd ${PLAN_DIR} \
&& go list -m all > /testground_dep_list

#:::
#::: (OPTIONAL) RUNTIME CONTAINER
#:::

## The 'AS runtime' token is used to parse Docker stdout to extract the build image ID to cache.
FROM ${RUNTIME_IMAGE} AS runtime
RUN apk add --no-cache bash gcompat curl
# PLAN_DIR is the location containing the plan source inside the build container.
ENV PLAN_DIR /plan


# HOME ENV is crucial for app/sdk -> remove at your OWN RISK!
ENV HOME /

COPY --from=builder /testground_dep_list /
COPY --from=builder ${PLAN_DIR}/testplan.bin /testplan

EXPOSE 9090 26657 26656 1317 26658 26660 26659 30000
ENTRYPOINT [ "/testplan"]
32 changes: 32 additions & 0 deletions testground/benchmark/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module github.com/crypto-org-chain/cronos/v2/testground

go 1.22

require github.com/testground/sdk-go v0.3.0

require (
github.com/avast/retry-go v2.6.0+incompatible // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/influxdata/influxdb1-client v0.0.0-20200515024757-02f0bf5dbca3 // indirect
github.com/klauspost/compress v1.10.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_golang v1.7.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.10.0 // indirect
github.com/prometheus/procfs v0.1.3 // indirect
github.com/raulk/clock v1.1.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/testground/sync-service v0.1.0 // indirect
github.com/testground/testground v0.5.3 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
go.uber.org/zap v1.16.0 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
google.golang.org/protobuf v1.25.0 // indirect
nhooyr.io/websocket v1.8.6 // indirect
)
Loading

0 comments on commit 9ad2ad7

Please sign in to comment.