Skip to content

Conversation

@DeviaVir
Copy link
Contributor

No description provided.

@DeviaVir DeviaVir self-assigned this Sep 22, 2025
@DeviaVir DeviaVir force-pushed the prom-503 branch 3 times, most recently from c16df88 to 1e386b9 Compare September 23, 2025 08:18
@DeviaVir DeviaVir changed the base branch from prerenderer-head-patch to master September 23, 2025 08:22
@DeviaVir DeviaVir force-pushed the prom-503 branch 2 times, most recently from 28abae1 to 44647ba Compare September 23, 2025 08:23
@DeviaVir DeviaVir requested a review from Copilot September 23, 2025 09:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Prometheus metrics support and overload protection to the prerender server. The implementation prevents server overload by limiting concurrent renders and provides monitoring capabilities through metrics.

  • Adds Prometheus client for collecting metrics on active renders, total renders, and render duration
  • Implements overload protection by limiting concurrent renders to 2x CPU count across cluster workers
  • Exposes metrics endpoint for monitoring server performance

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
prerender-server/src/server.js Adds Prometheus metrics collection and overload protection logic
prerender-server/src/cluster.js Implements cluster-level render limiting with message passing
prerender-server/package.json Adds prom-client dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +69 to +93
if (typeof process.send === 'function') {
const requestId = ++requestCounter
process.send({ type: 'startRender', requestId })
let responded = false
const handler = (msg) => {
if (msg.requestId === requestId && !responded) {
responded = true
clearTimeout(timeout)
process.removeListener('message', handler)
if (msg.type === 'renderAllowed') {
doRender()
} else if (msg.type === 'renderDenied') {
res.status(503).send('Server overloaded')
}
}
}
process.on('message', handler)
const timeout = setTimeout(() => {
if (!responded) {
responded = true
process.removeListener('message', handler)
console.error('IPC timeout for request', requestId)
res.status(500).send('Internal server error')
}
}, 5000) // 5 second timeout
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

The requestCounter increment operation is not atomic and could cause race conditions in concurrent scenarios. Consider using a more robust method for generating unique request IDs or implement proper synchronization.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ++requestCounter is atomic in Node.js since each worker is single-threaded, and requests are processed sequentially in the event loop. No race conditions possible per worker.

The counter is unique per worker, and since IPC is worker-to-master, it works correctly.

The code is solid as-is.

@DeviaVir DeviaVir merged commit f1a118c into master Sep 24, 2025
3 checks passed
@DeviaVir DeviaVir deleted the prom-503 branch September 24, 2025 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants