Skip to content

Balancing Website & Worker Workload (Performance) #1

@gamemann

Description

@gamemann

Recently, I've been trying to tune the query system we have in-place to update as many servers as possible.

Goal

  • Allow the separate worker app repsonsible for adding/updating servers, players, and stats to utilize as much database resources as possible without impacting the main website's database performance.
  • Try to have all servers scanned and updated within 5 - 10 minutes.
    • There are 50,000+ servers to scan right now.
    • The query program itself isn't the issue, the issue is finding a balance with things like pool sizes, connection limits, etc. for both the main website and worker app so that the worker app doesn't hurt the performance of the main website's queries.

Initial Setup

Until today, I used the built-in Prisma operations to add and update servers, players, etc. Locally, this worked great because my home server has a processor with high single-threaded performance (an Intel i7-12700K). However, in production, while the server has many more cores, the cores aren't rated well for single-threaded performance.

Since Node is single-threaded, this created a big bottleneck. Even running the worker app in a custom cluster mode so that there are multiple node processes, it was still choking using 4+ cores.

Last night, I ended up converting the built-in Prisma logic in the worker app to raw PostgreSQL queries which was a HUGE pain by the way, but was definitely worth it given Node is certainly not a bottleneck anymore.

Current Issue

Since the ridiculous overhead from the Prisma queries is no longer an issue (due to slow single-threaded performance), the PostgreSQL processes/threads consume all of the resources.

This allows our query scanner to update all online servers within <10 minutes. However, while it's updating servers, the main website seems to load the server list a bit slow. I haven't seen any issues when loading server pages (because it's a simple select query), but the server browser is obviously important.

Dedicated Pools & Such

I ended up setting up pgbouncer and creating dedicated pools for the main website and worker.

Now, it's about finding the best settings for this. Additionally, the add/updates supports batching and such, but I've found large batches causes issues so it's fairly low anyways.

Metadata

Metadata

Assignees

Labels

serversIssues and dev tracking related to servers.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions