N
Nuxt16mo ago
bnason

Server side worker thread

Is it possible/safe to create a server side worker thread for a long running up intensive task? If multiple of these tasks run, it slows down the responsiveness of the web interface. Hopefully moving them to their own threads should resolve that
8 Replies
akaSECTION
akaSECTION16mo ago
up Also, I have similar case, not for intensive task, but rather a background job. Is there a way to build a worker JS file on server-side and reference them so we can spawn the worker?
taunoha
taunoha16mo ago
It sounds like you need a WebSocket or a stream on the server. Then, you could use the useState composable to react to changes. In one of my projects, I needed to check the user's data (are there active contracts etc.). For that purpose, I created a plugin that will hydrate the data and the pages will just react to the changes to the state.
bnason
bnasonOP16mo ago
Well I'm running 100,000s of small worker jobs that are using a lot of cpu so my process starts to slow down responding to web requests. if I can run them on a second cpu, my main web response should get better. I know there is a node feature called worker threads, but that I believe just launches a single file as a new thread basically. So that code wouldn't have access to anything in Nuxt. I wish there were a way to add cli commands to nuxt, that way the worker could boot up with everything availble to Nuxt
akaSECTION
akaSECTION16mo ago
hmm in your case, isn't that better to entirely separate the worker process into different pid? then bridge both of them via IPC?
bnason
bnasonOP16mo ago
I guess the hard part here is having the worker have access to stuff that gets setup in nuxt, IE db, redis connections etc. At least without re-implementing that outside Nuxt
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
bnason
bnasonOP11mo ago
@brian7ng Just checking up on this. Are you a developer for Nuxt? Should I create a GitHub issue for this? I'm coming back to trying to resolve this in my project and really need to figure out a solution.
bnason
bnasonOP11mo ago
GitHub
Server side threads · nuxt nuxt · Discussion #25870
I'm looking for a way to create a server side thread. I have a BullMQ queue setup that processes hundreds of thousands of jobs and it causes the server to respond slowly when its working. The m...
Want results from more Discord servers?
Add your server