Bag of tasks, Operating System

The producer-consumermodel above has a standard human analogy of an assembly line. Humans have specialized skills, however, whereas threads running the same program do not need to be specialized: every thread has access to the same code and data. So any thread could do the work of any other thread.

In the bag of tasks approach, we have a collection of mostly independent "worker threads"; we no longer need to have different types of threads (one for the parser, one for the workers, etc). A bag of tasks system is very simple: every time a worker doesn't have anything to do, it goes to the bag of tasks and gets something to work on; in our web server example, this bag of tasks could contain new connections to be processed.

The advantage of the bag of tasks approach is that we can imagine all workers as being homogeneously implemented, each one running a speci?c piece of code depending on the type of the task it has to process at that time (imagine each worker as being implemented with a big switch statement).

Let us now present a way to convert the pseudo-code for the web server, given in the ?rst section, to a Bag of Tasks style. Assume we have an addWork thread and a bunch of worker threads.

addWork thread(): // only one thread of this type
wait connection
worker thread(): /// there will be a bunch of these threads
url = bag.poll()
look up url contents in cache
if (!in cache)
fetch from disk
put in cache
send data to client

The bag of tasks approach seems to exploit the available parallelism well, and it is easier to program and to extend. It has one major performance drawback, however, namely that there is only one lock protecting the bag; this implies contention. Also, imagine for instance that some of the workers are pretty quick; it could be the case that they acquire the lock, ?nish processing, release the lock, re-acquire it, etc. The problemnow is that each worker would be, itself, a new bottleneck.


Posted Date: 3/13/2013 3:06:28 AM | Location : United States

Related Discussions:- Bag of tasks, Assignment Help, Ask Question on Bag of tasks, Get Answer, Expert's Help, Bag of tasks Discussions

Write discussion on Bag of tasks
Your posts are moderated
Related Questions
Define the Main reason to encrypt a file Major reason to encrypt a file is secure it for transmission.

Q. It is occasionally said that tape is a sequential-access medium whereas magnetic disk is a random-access medium. In fact the correctness of a storage device for random access d

Q. Show that a few schedules are possible under the two-phase locking protocol however not possible under the timestamp protocol and vice versa. Answer: A schedule that is auth

Explain the Sleep (ms) Function  This call places the current thread in a suspended state for the number of milliseconds passed as the parameter (ms). After that Windows NT wil

Consider a particular system that does not have an interrupting clock.  The only way a thread can lose the processor is to voluntarily surrender it.  Additionally, the operating sy

Do ratio analysis by comparing the four companies financial statements, analysis and interpretation on the four-basic group : (Refer to attachment A) Liquidity ratio Asset

Is disk scheduling, other than FCFS scheduling, useful in a single-user environment? Explain your answer. In a single-user environment, the I/O queue usually is blank. Requests

The drawbacks of fixed partitioning are: The number of partitions are précised at system generation time limits the number of active processes in the system. For the re

Q. How Program execute in operating system? Program execution- The operating system fills the contents (or sections) of a file into memory as well as begins its execution. A us

Question: (a) i. Consider Active Directory as a database, then for each type and new class of objects, what is created? ii. What is the purpose of the global catalog? ii