Bag of tasks, Operating System

Assignment Help:

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
while(true)
wait connection
bag.put(url)
worker thread(): /// there will be a bunch of these threads
while(true)
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.

 


Related Discussions:- Bag of tasks

Determine the requiring variables on the scope of a thread, Determine the R...

Determine the Requiring Variables on the Scope of a Thread It is very common in server application programs to require variables on the scope of a thread. To provide such a sco

Describe the possible rmi invocation semantics, Question: (a) Explain t...

Question: (a) Explain the similarities and differences between two different threads running in the same process and two independent processes. When would you want to use two t

Define action that implementing meaning of instruction, Determine how Actio...

Determine how Action implementing instruction’s meaning are a actually carried out   Action implementing meaning of instruction are a actually carried out Instruction executio

Explain how a domain user account is authenticated, Question: a) The fo...

Question: a) The following questions pertain to User and Group accounts in Windows XP: i) Give four differences between a Power User and a Guest User account. ii) Explain h

Semaphores, Synchronization can be achieved by means other than locks and c...

Synchronization can be achieved by means other than locks and condition variables. One alternative is semaphores. A semaphore is used to regulate traf?c in a critical section. A se

What happens when you high-level format a floppy disk, Question: a. The...

Question: a. The following questions refer to a generic Windows file system: i) Describe what happens when you high-level format a floppy disk? ii) What is the maximum size

Explain first fit allocation algorithm, Describe the following allocation a...

Describe the following allocation algorithms: a. First fit b. Best fit c. Worst fit   a. First-fit: search the list of available memory and all

Define caching, Define caching. A cache is a region of fast memory that...

Define caching. A cache is a region of fast memory that holds copies of data. Access to the cached copy is well-organized than access to the original. Caching and buffering are

Direct memory access, A-  In a table format, compare between Programmed I/O...

A-  In a table format, compare between Programmed I/O, Interrupt -driven I/O, and Direct Memory Access (DMA) in terms of basic idea, Advantages, disadvantages, and the operating en

Buffer, What is bounded buffer

What is bounded buffer

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd