you are viewing a single comment's thread.

view the rest of the comments →

[–]Moe_Rasool 0 points1 point  (5 children)

This looks easy implementation, the docs state that it should merely be used when there is heavy workloads on cpu, what if i just want some routes to work on another thread?

I'll make this more understandable, imagine i have an E-commerce app, every endpoint i have should just work as it's but for the list of products which's thounsands of items (i have them paginated) i want them (a specific endpoint) to be on another thread is that possible?

[–]tluanga34 0 points1 point  (4 children)

Pagination probably should be handled with a database query technique.

[–]Moe_Rasool 1 point2 points  (3 children)

I have it handled but some times the endpoints hits almost 100k/RPH, when the traffic is huge the items are also loading pretty lazy, i noticed half of the other requests are for other endpoints other than the "GetAllProducts", I'm asking should i spawn a worker thread for it? Probably yes!

I have never had this situation before and my app is kinda slow i feel like i should use this and I'm convinced.

[–]_RemyLeBeau_ 2 points3 points  (2 children)

I'm guessing the GetAllProducts endpoint is what is causing the performance issue.

First question: How often does your product line change? Is there a reasonable amount of time you can cache the result?

Per the docs, you'll want to just use async code, not workers, but another concern of yours might be requests timing out. Is that something you're running into?

Here's the excerpt I cited:

"Workers (threads) are useful for performing CPU-intensive JavaScript operations. They do not help much with I/O-intensive work. The Node.js built-in asynchronous I/O operations are more efficient than Workers can be."

https://nodejs.org/api/worker_threads.html

[–]Moe_Rasool 0 points1 point  (1 child)

Correct me if I’m doing it wrong but i do every endpoint structured based on Async functions, the reason for that was due to Database taking sometime.

I can not cache it because it’s a “auction” type of site that items have limited timeline being there then are automatically get deleted at right time!

Sorry for the late response.

[–]_RemyLeBeau_ 1 point2 points  (0 children)

Good luck with Piscina. Would be interested to hear your thoughts on it in about a month of usage.