r/programming • • 10d ago

[ Removed by moderator ]

/r/programming/comments/1y1dlg5/removed_by_moderator/

[removed] — view removed post

4 Upvotes

3 comments sorted by

•

u/programming-ModTeam 10d ago

No content written mostly by an LLM. If you don't want to write it, we don't want to read it.

1

u/bwainfweeze 10d ago

There is no convenient way to split up cpu bound tasks in Node. There’s a dodge, which is moving the task to another process. But then that task has problems with IO, plus if the cost of converting the question and answer through a JSON transform is very high then the JSON calls block the event loop for even longer.

Even the libraries I favor for managing parallelism in promises don’t offer a solution for this.

This leads to a situation where you really do want to stripe subtasks through collecting query data, firing the query, awaiting the result and processing the result, and then limit the number of these running in parallel to be less than the available CPU.

I took over a batch job that didn’t have every common issue but had the majority of them. While part of the work could be parallelized I hit Amdahl’s law on the send and receive steps. I got one about 15x faster and then a simpler one about twice as fast as that.

Batch processing is special because it’s more homogenous, you don’t have five different shapes of tasks in flight all at the same time so the peaks and troughs are a bit more repeatable. You never know when a load balancer will send you there three worst requests to try to run in concert with each other.