-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add persistence to the stress tests (#703)
closes #659 closes #603 Test plan: run ./packages/stress/scripts/start_redis.sh ./packages/stress/scripts/localhost_chat_setup.sh ./packages/stress/scripts/localhost_chat.sh then run ./packages/stress/scripts/localhost_chat_setup.sh a few more times see "globalRunIndex" increment up in the reply see "timeToShareKeys": "2ms", drop to nearly 0 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a task for "Start Stress Testing Redis" in the development environment. - Introduced scripts for managing Redis containers (`start_redis.sh`, `stop_redis.sh`). - Implemented Redis storage capabilities in the chat stress testing module. - **Documentation** - Improved clarity and usability in the README for the `packages/stress` module. - **Bug Fixes** - Enhanced error handling and environment variable management in various scripts. - **Refactor** - Updated functions and interfaces to support Redis integration and improved state management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
15 changed files
with
190 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
# Stress | ||
|
||
Running things in jest comes with like a huge amount of overhead per process. No f'ing clue what it's doing. Running things in node with custom-loader.mjs takes less overhead. (from looking at Activity Monitor while running clients) | ||
|
||
Times simpile test just printing out os stats: | ||
## Run it locally | ||
|
||
``` | ||
jest: 731.20s user 196.02s system 765% cpu 2:01.08 total | ||
node: 119.62s user 17.02s system 779% cpu 17.533 total // 7x speedup!!! | ||
./scripts/localhost_chat_setup.sh && ./scripts/localhost_chat.sh | ||
``` | ||
|
||
# Directions | ||
### Totally optional, if you want to test persistence | ||
|
||
Use files in scripts dir to launch load tests | ||
``` | ||
./scripts/start_redis.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
redis: | ||
image: redis:latest | ||
container_name: stress-redis | ||
ports: | ||
- '6379:6379' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" | ||
cd .. | ||
|
||
echo "stress/scripts/start_redis.sh" | ||
|
||
# Specify the name or ID of the Docker container you want to stop | ||
container_name="stress-redis" | ||
|
||
# Check if the container is running | ||
if docker ps --filter "name=$container_name" --format '{{.ID}}' | grep -qE "^[0-9a-f]+$"; then | ||
# The container is running, so stop it | ||
|
||
echo "Container $container_name is already running." | ||
else | ||
echo "Starting $container_name." | ||
|
||
# write the environment variables to a file so the tests can load it | ||
FILE="./scripts/.env.storage" | ||
ENV_VAR="REDIS_HOST=http://localhost:6379" | ||
echo $ENV_VAR >> $FILE # hard coded port from the docker compose file | ||
|
||
docker-compose -p "stress" -f ./scripts/docker_compose_redis.yml up | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" | ||
cd .. | ||
|
||
echo "stress/scripts/stop_redis.sh" | ||
|
||
# remove the .env.storage file | ||
rm -f ./scripts/.env.storage | ||
|
||
# Specify the name or ID of the Docker container you want to stop | ||
container_name="stress-redis" | ||
|
||
# Check if the container is running | ||
if docker ps --filter "name=$container_name" --format '{{.ID}}' | grep -qE "^[0-9a-f]+$"; then | ||
# The container is running, so stop it | ||
docker stop "$container_name" | ||
echo "Container $container_name stopped." | ||
else | ||
echo "Container $container_name is not running." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { dlogger } from '@river-build/dlog' | ||
import Redis from 'ioredis' | ||
|
||
const logger = dlogger('stress:storage') | ||
|
||
export interface IStorage { | ||
get(key: string): Promise<string | null> | ||
set(key: string, value: string): Promise<void> | ||
remove(key: string): Promise<void> | ||
close(): Promise<void> | ||
} | ||
|
||
export class RedisStorage implements IStorage { | ||
private client: Redis | ||
|
||
constructor(uri: string) { | ||
const url = new URL(uri) | ||
const host = `${url.protocol}//${url.hostname}` | ||
const port = parseInt(url.port) | ||
const opts = host.includes('localhost') ? { port } : { host, port } | ||
this.client = new Redis(opts) | ||
} | ||
async get(key: string): Promise<string | null> { | ||
try { | ||
const r = await this.client.get(key) | ||
return r | ||
} catch (error) { | ||
logger.error(`Failed to get key ${key}:`, error) | ||
return null | ||
} | ||
} | ||
async set(key: string, value: string): Promise<void> { | ||
try { | ||
await this.client.set(key, value) | ||
} catch (error) { | ||
logger.error(`Failed to set key ${key} with value ${value}:`, error) | ||
} | ||
} | ||
async remove(key: string): Promise<void> { | ||
try { | ||
await this.client.del(key) | ||
} catch (error) { | ||
logger.error(`Failed to remove key ${key}:`, error) | ||
} | ||
} | ||
|
||
async close() { | ||
try { | ||
await this.client.quit() | ||
} catch (error) { | ||
logger.error('Failed to close Redis connection:', error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.