Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '18, 20, 22, 24'
version: '18, 20, 22, 24, 25'
install: npm run install-wrk > wrk.log && npm install && cat /proc/cpuinfo
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"egg1": "npm:egg@1",
"egg2": "npm:egg@2",
"egg3": "npm:egg@3",
"egg4": "npm:egg@beta",
"koa": "^2.13.4",
"koa-router": "^12.0.0",
"nunjucks": "^3.0.1"
Expand All @@ -34,5 +35,6 @@
"url": "https://github.com/eggjs/benchmark.git"
},
"author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
"license": "MIT"
}
"license": "MIT",
"packageManager": "npm@11.7.0"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The file is missing a newline character at the end. It's a common convention to end files with a newline to avoid issues with file concatenation and some command-line tools.

Suggested change
}
}

19 changes: 17 additions & 2 deletions simple/dispatch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const egg4 = require('egg4');
const egg3 = require('egg3');
const egg2 = require('egg2');
const egg1 = require('egg1');
Expand All @@ -9,9 +10,8 @@ if (workers > 4) {
workers = 4;
}

if (cluster.isMaster) {
if (cluster.isPrimary) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

You've updated cluster.isMaster to cluster.isPrimary. While this is a good practice for modern Node.js versions, cluster.isPrimary was only introduced in Node.js v16.0.0. The package.json specifies "node": ">=14.20.0", which means this code will fail on Node.js v14 and v15. To ensure backward compatibility, you should check for both properties.

Suggested change
if (cluster.isPrimary) {
if (cluster.isPrimary || cluster.isMaster) {

console.log('os version: %s', os.version());
console.log('egg-cluster version: %s', require('egg-cluster/package.json').version);

egg1.startCluster({
workers,
Expand Down Expand Up @@ -59,6 +59,21 @@ if (cluster.isMaster) {
reusePort: true,
});

egg4.startCluster({
workers,
baseDir: __dirname,
port: 7010,
framework: 'egg4',
});

egg4.startCluster({
workers,
baseDir: __dirname,
port: 7011,
framework: 'egg4',
reusePort: true,
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These two calls to egg4.startCluster are very similar and contain duplicated code. To improve maintainability, consider refactoring this into a loop to avoid repetition.

  [
    { port: 7010 },
    { port: 7011, reusePort: true },
  ].forEach(config => {
    egg4.startCluster({
      workers,
      baseDir: __dirname,
      framework: 'egg4',
      ...config,
    });
  });


Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The egg4 server with reusePort on port 7011 is started in dispatch.js but the corresponding benchmark test is commented out. This creates an inconsistency where the server runs but is never tested. Either uncomment the benchmark test or remove the server configuration from dispatch.js.

Suggested change
egg4.startCluster({
workers,
baseDir: __dirname,
port: 7011,
framework: 'egg4',
reusePort: true,
});

Copilot uses AI. Check for mistakes.
for (let i = 0; i < workers; i++) {
cluster.fork();
}
Expand Down
55 changes: 41 additions & 14 deletions simple/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ curl 'http://127.0.0.1:7005/'
curl 'http://127.0.0.1:7006/'
curl 'http://127.0.0.1:7008/'
curl 'http://127.0.0.1:7009/'
# egg4
curl 'http://127.0.0.1:7010/'
curl 'http://127.0.0.1:7011/'

test `tail -c 1 $CSV` && printf "\n" >> $CSV
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Make the CSV newline append safe when the file doesn’t exist (and quote vars).
test \tail -c 1 $CSV`is brittle and will error if$CSV` is missing.

-test `tail -c 1 $CSV` && printf "\n" >> $CSV
+if [[ -f "$CSV" ]] && [[ -s "$CSV" ]] && [[ "$(tail -c 1 -- "$CSV")" != $'\n' ]]; then
+  printf "\n" >> "$CSV"
+fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test `tail -c 1 $CSV` && printf "\n" >> $CSV
if [[ -f "$CSV" ]] && [[ -s "$CSV" ]] && [[ "$(tail -c 1 -- "$CSV")" != $'\n' ]]; then
printf "\n" >> "$CSV"
fi
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 47-47: Quote this to prevent word splitting.

(SC2046)

🤖 Prompt for AI Agents
In simple/run.sh around line 47, replace the brittle backticked tail call with a
safe existence/size check and quoted variable usage: first test that "$CSV"
exists/is non-empty (e.g. using [ -s "$CSV" ] or [ -f "$CSV" ] as appropriate),
then run tail (with -- and "$CSV" quoted) or otherwise append a newline only
when the file exists; ensure all references to $CSV are quoted and the printf >>
operation appends to the quoted "$CSV".


Expand All @@ -33,9 +36,9 @@ echo "------- egg3 hello with reusePort=true -------"
echo ""
print_head "egg3" "egg3 hello with reusePort=true"
wrk 'http://127.0.0.1:7008/' \
-d 30 \
-d 10 \
-c 50 \
-t 8 \
-t 4 \
--latency \
-s $REPORT

Expand All @@ -45,9 +48,9 @@ echo "------- egg3 hello -------"
echo ""
print_head "egg3" "egg3 hello"
wrk 'http://127.0.0.1:7005/' \
-d 30 \
-d 10 \
-c 50 \
-t 8 \
-t 4 \
--latency \
-s $REPORT

Expand All @@ -57,9 +60,9 @@ echo "------- egg3 hello with worker_threads=1 -------"
echo ""
print_head "egg3" "egg3 hello with worker_threads=1"
wrk 'http://127.0.0.1:7006/' \
-d 30 \
-d 10 \
-c 50 \
-t 8 \
-t 4 \
--latency \
-s $REPORT

Expand All @@ -69,21 +72,45 @@ echo "------- egg3 hello with worker_threads and reusePort=true -------"
echo ""
print_head "egg3" "egg3 hello with worker_threads and reusePort=true"
wrk 'http://127.0.0.1:7009/' \
-d 30 \
-d 10 \
-c 50 \
-t 8 \
-t 4 \
--latency \
-s $REPORT

sleep 5
echo ""
echo "------- egg4 hello -------"
echo ""
print_head "egg4" "egg4 hello"
wrk 'http://127.0.0.1:7010/' \
-d 10 \
-c 50 \
-t 4 \
--latency \
-s $REPORT

# sleep 5
# echo ""
# echo "------- egg4 hello with reusePort=true -------"
# echo ""
# print_head "egg4" "egg4 hello with reusePort=true"
# wrk 'http://127.0.0.1:7011/' \
# -d 10 \
# -c 50 \
# -t 4 \
# --latency \
# -s $REPORT
Comment on lines +129 to +139
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code is commented out. If this benchmark is not ready or intended to be run, it should be removed to avoid cluttering the script. Dead code can be confusing for future maintainers.


sleep 5
echo ""
echo "------- koa hello -------"
echo ""
print_head "koa" "koa hello"
wrk 'http://127.0.0.1:7002/' \
-d 30 \
-d 10 \
-c 50 \
-t 8 \
-t 4 \
--latency \
-s $REPORT

Expand All @@ -93,9 +120,9 @@ echo "------- egg1 hello -------"
echo ""
print_head "egg1" "egg1 hello"
wrk 'http://127.0.0.1:7003/' \
-d 30 \
-d 10 \
-c 50 \
-t 8 \
-t 4 \
--latency \
-s $REPORT

Expand All @@ -105,9 +132,9 @@ echo "------- egg2 hello -------"
echo ""
print_head "egg2" "egg2 hello"
wrk 'http://127.0.0.1:7004/' \
-d 30 \
-d 10 \
-c 50 \
-t 8 \
-t 4 \
--latency \
-s $REPORT

Expand Down