MCPcopy Index your code
hub / github.com/agile8118/node-1m-rps

github.com/agile8118/node-1m-rps @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
7 symbols 33 edges 12 files 1 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Overview

This is the main repository that we used in the Handling 1 Million Requests per Second Video.

Setup

To be able to run the code, you need to have Node.js, Redis, and Postgres installed.

Clone the repository and create a file in the database directory called keys.js and put the following content in there:

/**
 * If you have a freshly installed Postgres with the default config,
 * these should work even if you don't have the benchmark database
 * created. But if you have changed anything, like adding a password,
 * please make sure to specify the correct value.
 */
const keys = {
  dbUser: "<your-postgres-username>",
  dbHost: "localhost",
  dbDatabase: "benchmark",
  dbPassword: "",
  dbPort: 5432,
};

export default keys;

Once done, run this command from the root directory to install the dependencies:

npm install

Then, initialize the Postgres database by running:

npm run seed

Now, you can run either the Express.js, Fastify, or Cpeak version (all have the same logic). They are just 3 different frameworks for Node.js.

node cpeak.js

or node express.js or node fastify.js.

Then you should get a log like this:

Cpeak server running at http://localhost:3000
[redis] standalone ready.
[postgres] connected successfully to benchmark.

Redis cluster mode: If you want to run the app with Redis in cluster mode, use the redis.sh file to set it up.


Environment Variables

You can customize how the application runs by passing these 2 environment variables:

  • REDIS_CLUSTER to indicate whether the app should connect to Redis cluster mode or not. Default: "false"
  • PG_CONNECT to indicate whether the app should connect to Postgres database. Default: "true"

Example:

PG_CONNECT=false REDIS_CLUSTER=true node express.js

Output should be:

Express server running at http://localhost:3001
[redis] cluster ready. Total nodes 30 (masters: 15, replicas: 15)

Node.js Cluster Mode

If you want to run the app in cluster mode, you can use PM2 for it. Check first if you have pm2 installed by running pm2 --version and if you don't have it, install it by running npm install -g pm2.

Then you can start the app in cluster mode by running:

pm2 start ecosystem.config.cjs

Check the ecosystem.config.cjs to change the environment variables.

The above command will run the cpeak server by default. If you want it to run Express or Fastify instead, specify the F environment variable like this:

F=express pm2 start ecosystem.config.cjs

or F=fastify pm2 start ecosystem.config.cjs to start the Fastify server.

You can run pm2 logs to check the logs of the application when running in cluster mode.


Other Commands

When seeding the database, specify the -r option to indicate how many records should be added to the database:

npm run seed -- -r 20000000

This will insert 20 million records into the codes table.

To move all the Postgres data over to Redis, run:

npm run migrate

This does not work with Redis in cluster mode.

Core symbols most depended-on inside this repo

generateCode
called by 8
utils.js
getMaxId
called by 3
utils.js
syncWorker
called by 1
database/sync.js
createDatabase
called by 1
database/seed.js
insertSeed
called by 1
database/seed.js
migrate
called by 1
database/migrate.js
query
called by 0
database/index.js

Shape

Function 7

Languages

TypeScript100%

Modules by API surface

utils.js2 symbols
database/seed.js2 symbols
database/sync.js1 symbols
database/migrate.js1 symbols
database/index.js1 symbols

For agents

$ claude mcp add node-1m-rps \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact