Skip to content

Commit

Permalink
add load testing script and code
Browse files Browse the repository at this point in the history
  • Loading branch information
vordimous committed Feb 29, 2024
1 parent f89f037 commit 3c8ee45
Show file tree
Hide file tree
Showing 7 changed files with 881 additions and 123 deletions.
24 changes: 7 additions & 17 deletions taxi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,19 @@ The [Taxi UI](http://localhost/) highlights downtown San Jose, CA bars. Users ca

## Load Testing

The mqtt-simulation service includes a `default_routes.json` file, which starts a looping set of routes used in the demo. An additional file, `default_routes_load_test.json`, is available, which leverages the simulator's ability to generate multiple topics.
There is a `load_test.sh` script included that makes 14 unique requests the same as if the UI was using the "Hail Taxi" button.

1. You will see in the JSON file the config for managing the number of topics to generate by updating the `"RANGE_END"` value:

```json
"TYPE": "multiple",
"RANGE_START": 1,
"RANGE_END": 500,
```

1. The `taxi-service` in the [docker-compose.yaml](docker-compose.yaml) file mounts the default config. Update the volume mount to map the load_test file.
1. The `taxi-service` in the `docker-compose.yaml` has a `REPLICATION` env var that will duplicate the incoming taxi requests to produce the number of connected MQTT clients per request. Here for each new taxi request `10` new unique MQTT clients will be created and publish data.

```yaml
volumes:
- ./grpc/service/default_routes_load_test.json:/usr/src/app/default_routes.json
environment:
REPLICATION: 10
```
1. Ensure the `DEFAUlT_ROUTES` env var is `true` so the service will start the sim and the `PRINT_SIM_LOGS` is true so the container will print the simulator output.
1. Run the `load_test.sh` script.

```yaml
environment:
DEFAUlT_ROUTES: true
PRINT_SIM_LOGS: true
```sh
./load_test.sh
```

1. Happy Load Testing!
3 changes: 2 additions & 1 deletion taxi/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ services:
- ./grpc/service/default_routes.json:/usr/src/app/default_routes.json
environment:
PRINT_SIM_LOGS: false
DEFAUlT_ROUTES: true
DEFAUlT_ROUTES: false
REPLICATION: 300
BROKER_HOST: zilla
ports:
- 50051:50051
Expand Down
101 changes: 0 additions & 101 deletions taxi/grpc/service/default_routes_load_test.json

This file was deleted.

9 changes: 7 additions & 2 deletions taxi/grpc/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
brokerPort = env.GetIntDefault("BROKER_PORT", 7183)
printSim = env.GetBoolDefault("PRINT_SIM_LOGS", false)
defaultRoutes = env.GetBoolDefault("DEFAUlT_ROUTES", false)
replication = env.GetIntDefault("REPLICATION", 1)
logChannel = make(chan string)
)

Expand All @@ -36,6 +37,8 @@ type dataConfig struct {

type topicConfig struct {
Type string `json:"TYPE"`
RangeStart int `json:"RANGE_START"`
RangeEnd int `json:"RANGE_END"`
Prefix string `json:"PREFIX"`
TimeInterval int `json:"TIME_INTERVAL"`
Data []dataConfig `json:"DATA"`
Expand Down Expand Up @@ -127,7 +130,7 @@ func (s *taxiRouteServer) CreateTaxi(ctx context.Context, in *pb.Route) (*pb.Rou
endMark = append(endMark, -1)
coords.Values = append(coords.Values, endMark)

routeKey := fmt.Sprintf("taxi/%s/location", in.GetKey())
routeKey := fmt.Sprintf("taxi/%s", in.GetKey())
simConfig := simulatorConfig{
BrokerURL: brokerURL,
BrokerPort: brokerPort,
Expand All @@ -136,7 +139,9 @@ func (s *taxiRouteServer) CreateTaxi(ctx context.Context, in *pb.Route) (*pb.Rou
Qos: 0,
Topics: []topicConfig{
{
Type: "single",
Type: "multiple",
RangeStart: 1,
RangeEnd: replication,
Prefix: routeKey,
TimeInterval: int(in.GetDuration() / float64(len(coords.Values))),
Data: []dataConfig{
Expand Down
Loading

0 comments on commit 3c8ee45

Please sign in to comment.