Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between 'Web workers' and 'Background workers' on App Harbor

I'm developing the backend server for a turn based game using App Harbor and thus far it seems perfectly suited to my needs. I would really like to run a background process to process turn data etc and I was wondering if someone could clarify what the difference between 'Web workers' and 'Background workers' are? I have fairly limited experiance with web development, but as far as I can tell 'Web workers' are for interacting with AJAX pages (which I don't need) and 'Background workers' allow you to run a console application in the background (which I do need!)

Thanks!

like image 820
neworderofjamie Avatar asked Jun 23 '12 12:06

neworderofjamie


People also ask

Is web worker same as service worker?

What is a Service Worker? Unlike Web Workers, Service Workers have a dedicated role of being a proxy between the network and the browser and/or cache. Similar to Web Workers, they are registered in the primary JavaScript file as a dedicated worker.

What is a web worker used for?

Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface.

How many web workers Workers can run concurrently?

How many web workers can run concurrently JavaScript? A web worker is a JavaScript program running on a different thread, in parallel with main thread. The browser creates one thread per tab. The main thread can spawn an unlimited number of web workers, until the user's system resources are fully consumed.

Should I use web workers?

Web Workers help in making use of multi-core processors efficiently, otherwise, JavaScript Application ends up running on the single main thread. If you put this code into the browser console in Developer Tools, you will see that the page becomes unresponsive which is due to the code blocking the main thread.


2 Answers

Web workers is connected with the request from browser and can get and send data to the request on browser.

Background Workers are independent threads that are not connected with any request and can not send data to the browser alone*.

[*] Only through a web worker.

like image 191
Aristos Avatar answered Oct 07 '22 17:10

Aristos


In general 'Web worker' is the web application, or the ASP.NET site/service that handles requests from user. 'Background worker' is simply a scheduled task. It runs in background, on specified intervals, and executes some code.

The difference is that a Web worker does some work when a new request comes to the application. A request means someone loads a page/calls a web service on ASP.NET. While the background worker is being started on some interval, and doesn't need a user to load a page to be executed. It is mostly used for processing long-running tasks. The usual workflow is - the web worker receives a request from the user, and queues some data to be processed. On next run, the background worker gets the data and processes it, and stores the data somewhere(usually in database). Then the web worker, on next request from user, checks the database and if the result is there - shows it to the user.

This way the user doesn't need to wait for the asp.net page to process the data and return a result immediately.

like image 27
Tisho Avatar answered Oct 07 '22 15:10

Tisho