Benchmark performance #862
-
Hi! I'm running a simple app, this is the main code import HyperExpress from 'hyper-express'
import { MongoClient } from 'mongodb'
const webserver = new HyperExpress.Server()
const mongoClient = new MongoClient("mongodb://mongo:mongo@bench_he_db")
mongoClient.connect()
const db = await mongoClient.db('bench')
// Create GET route to serve 'Hello World'
webserver.get('/', async (request, response) => {
response.send('Hello World');
})
webserver.get('/bench', async (request, response) => {
const articles = await db.collection('articles')
let ids = []
let q = 50
while (q--) {
ids.push(parseInt(Math.random() * 100000))
}
const data = await articles.find({ n: { $in: ids } }).toArray()
// console.log(data)
return response.send(JSON.stringify(data))
// return response.send(JSON.stringify({a:1}))
})
webserver.listen(8000)
.then((socket) => {
console.log('Webserver started on port 8000')
})
.catch((error) => console.log('Failed to start webserver on port 8000', error));
basically retrieving 50 random docs from a mongodb database where we have already 100k documents, NOTE1: i tried a simple {hello: "World"} without accessing the db and on 25% CPU load uWebSockets gives me about 200000 reqs/s Can't get if the issue is on the mongo driver side (although i used the same driver for fastify) or on the framework itself, or maybe i did something wrong )? IF you have any idea, please let me know. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
None of this is uWS. I don't know why it is reported here. Report issues in respective projects, not here. What I can add, however, is that ab (ApacheBench) is a tool written in the 1990s for HTTP1.0 which is a deprecated protocol nobody should be using, and not supported by uWS so it's not supposed to work. uWS implements the latest RFC for HTTP1.1. If you want some more competent usage of uWS, you can look at Bun and its DB connectors - I cannot be responsible for whatever MongoClient or HyperExpress does wrong. |
Beta Was this translation helpful? Give feedback.
-
Logically, HyperExpress is not uWS. Whatever it does, is irrelevant. It's not my product. I looked in it's source a bit and found several performance issues - one major being that responses are not corked properly. This is a major performance mistake, esp. for some "helper" library. The second being that responses are deferred in some event listener thingy. None of this is representative of uWS. |
Beta Was this translation helpful? Give feedback.
-
Wherever you have await in your handler, you must use res.cork to properly cork the response otherwise performance is going to be crap. In v21 this will be enforced because so many people ignore that in the user manual |
Beta Was this translation helpful? Give feedback.
Wherever you have await in your handler, you must use res.cork to properly cork the response otherwise performance is going to be crap. In v21 this will be enforced because so many people ignore that in the user manual