Reputation: 382
I have such a code and I want to do a load test on it to see how many open connections it can handle at the same time. How can I do this?
app.get('/stream', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
res.flushHeaders();
const clientId = uuidv4();
const newClient = {
id: clientId,
res,
};
clients.push(newClient);
console.log(`New client connected: ${clientId}. Total clients: ${clients.length}`);
req.on('close', () => {
console.log(`Client ${clientId} closed connection. Worker ${process.pid}`);
clients = clients.filter((client) => client.id !== clientId);
});
if (currentData) {
res.write(`data: ${JSON.stringify(currentData)}\n\n`);
}
});
Upvotes: 0
Views: 39