По моему мнению, JS представляет собой однопоточный язык, выполняет только сегмент кода за раз, поэтому QPS составляет 166,66 (1000 мс /6 мс). < /p>
и если есть какая-то асинхронная логика в среде на стороне сервера, как < /p>
Код: Выделить всё
await new Promise((resolve, reject) => setTimeout(() => resolve(), 200))
< /code>
Тогда QPS должен быть 133 (1000 мс - 200 мс /6 мс). < /p>
Итак, вот проблема < /p>
// In Next.js
function Home(props: any) {
return (
Welcome to the Test Page
)
}
export const getServerSideProps = async (content: any) => {
const ctx = content.req.ctx
const res = await new Promise((resolve, reject) => setTimeout(() => resolve(true), 200))
return {
props: {
ctx: ctx,
},
}
}
export default Home
< /code>
// in index.js (run this index.js as server instead run the stock next.js server)
nextApp.prepare()
.then(() => {
app.use((req, res, next) => {
const start = performance.now();
handler(req, res).catch(next);
if (req.url === '/test') {
res.on('finish', () => {
const duration = performance.now() - start;
console.log(`[SSR] ${req.method} ${req.url} took ${duration.toFixed(2)}ms`);
});
}
});
app.listen(PORT, () => {
console.log(`🚀 Server ready at http://localhost:${PORT}/`);
});
})
.catch(err => {
console.error("❌ Error with starting the server", err);
});
< /code>
the result be like below
🚀 Server ready at http://localhost:4000/
[SSR] GET /test took 213.54ms
[SSR] GET /test took 211.57ms
[SSR] GET /test took 214.70ms
[SSR] GET /test took 207.68ms
[SSR] GET /test took 209.08ms
[SSR] GET /test took 207.52ms
[SSR] GET /test took 210.00ms
[SSR] GET /test took 212.28ms
[SSR] GET /test took 217.28ms
[SSR] GET /test took 204.89ms
[SSR] GET /test took 204.49ms
[SSR] GET /test took 206.33ms
< /code>
JS excute code and response a html took 6 ~ 13ms (minus await 200ms), let's say it took 9ms per request
But when I try to use abab -n 100 -c 100 http://localhost:4000/test
< /code>
the result is like
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software:
Server Hostname: localhost
Server Port: 4000
Document Path: /test
Document Length: 1446 bytes
Concurrency Level: 100
Time taken for tests: 0.477 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 172500 bytes
HTML transferred: 144600 bytes
Requests per second: 209.84 [#/sec] (mean)
Time per request: 476.544 [ms] (mean)
Time per request: 4.765 [ms] (mean, across all concurrent requests)
Transfer rate: 353.50 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 0.6 2 3
Processing: 209 247 15.1 247 266
Waiting: 205 242 17.0 245 266
Total: 209 249 14.7 249 268
Percentage of the requests served within a certain time (ms)
50% 249
66% 254
75% 267
80% 267
90% 267
95% 267
98% 268
99% 268
100% 268 (longest request)
< /code>
In my understanding, it's be like 1000ms - 200ms (await) = 800ms
so 800ms / 9ms = 88.8
but the QPS of result of ab test is a lot higher than my estimate.
I don't know - am I even right?
Подробнее здесь: https://stackoverflow.com/questions/796 ... pplication
Мобильная версия