SlideShare a Scribd company logo
1 of 19
Server Architecture Models
Operating Systems
Hebrew University
Spring 2004
Fork-exec model
Server Behavior
Drawbacks
1. This multiprocessing architecture is useful if the
handling of the client request takes some time or a
session state has to be kept by the (child) server
2. HTTP, however, is a stateless protocol. No session
information needs to be kept by the server
3. An HTTP server based on that architecture would be
inefficient
– The master server would have to create a process for each
HTTP connection, which would handle this one connection only
and then die
– While the master server creates a process it cannot accept
incoming requests – a bottleneck for the entire server.
Pre-Forking Model –
The leader-followers pattern
The preforking architecture
is based on a pool of tasks
(processes or threads)
which are playing 3 different
roles:
•wait for requests (listener)
•process a request (worker)
•queue in and wait to
become the listener (idle
worker)
•The listener is the leader,
the idle workers are the
followers
Win32/WinNt MPM
• Uses threads (a lot more performant than Win
processes)
– The number of threads is fixed, since idle threads impose almost
no performance issue
• There are two Windows processes in this
multitasking architecture:
– At restart, the master process creates the child process
– The worker process (child server process) contains the threads
which handle the requests,
– while the supervisor process (master process) makes sure that
the worker process works correctly
– For connection distribution to the workers a job queue is used
Win32/WinNt MPM cont.
• The master-child connection is done via
events
– master to child: shutdown, restart
– child to master: need restart, error that requires
shutdown
• Worker process’ threads:
– master thread – starts one or multiple listeners
– listener(s) thread(s) – accept requests and put into
the job queue
– worker threads – read from the queue and handle
requests (by calling some routine)
Win32/WinNt MPM
MPM for Linux/Unix
• Combine a multiprocessing and a
multithreading model:
– a variable number of processes, which include a
fixed number of threads
– pre-forking model on process level and job queue
model on thread level
– each child process incorporates a listener thread
• The master server creates the child
process, which starts a starter thread that
set up all worker threads and a single
listener thread
MPM for Linux/Unix cont.
• Within each child process, the
communication between the listener and all
worker threads is organized with two
queues:
– the job queue
– the idle queue
• Advantages of this approach are that it
combines:
– the stability of multiprocessing
– the high performance of multithreading
MPM for Linux/Unix
Thread Pool
1. Create a number of threads at process startup and
place them into a pool where they sit and wait for work.
• e.g. for multithreading a web server.
2. A thread from the pool is activated on the request, and
it returns to the pool on completion.
3. Benefits of thread pool:
– Faster service
– Limitation on the number of threads, according to the need.
4. Thread-pool-architecture allows dynamic adjustment
pool size.
Thread Pool Model for Ex4
• From the exercise definition:
Build a multithreaded server.
The main thread will handle user input,
second thread will handle load balancing
between computation threads, additional
three threads will be used to compute
prime numbers, and the last thread will
handle all output.
Thread Pool Model for Ex4
user
output thread
Main
thread
computation
thread
balancing
thread
input
computation
thread
computation
thread
thread creation
int pthread_create(pthread_t *thread, pthread_attr_t *attr,
void* (*start_routine)(void*), void *arg);
thread – pointer to the new thread
attr – the new thread attributes, usually NULL (i.e. system
thread that we can do ‘join’ on it = wait to his end).
start_routine – pointer to the function that is the thread
code, the return value of that function is the end value of
the thread
arg – parameter for the start_routine function
mutex locks
int pthread_mutex_lock(pthread_mutex_t *mutex);
– blocks until the mutex is free, and than locks it
int pthread_mutex_trylock(pthread_mutex_t *mutex);
– fails if the mutex is already locked, otherwise – locks it
int pthread_mutex_unlock(pthread_mutex_t *mutex);
– frees (unlocks) the mutex
Event-driven
• The main program creates acceptors.
• Each acceptor creates event-handler for
each event it is interested in, and the
handler registers for this event.
• The main program listens for events.
• When event occurs, the appropriate
acceptor is notified, notify the handler,
which handle the event.
Event-driven cont.
• Advantages:
– services can run independently
– integrating new services is easy
– a programmer can do his own ‘task management’ and
save context switching (context is saved in the data
structure)
• Drawbacks:
– resource management problems if requests arrive
faster than they are processed
– big overhead for system with short-duration services
– harder to implement than other models
References
Apache Modeling Portal
http://apache.hpi.uni-potsdam.de/document/4_3Multitasking_server.html
Efficient Architectures for object-oriented
component based Middleware
http://www.stal.de

More Related Content

What's hot (15)

Multithreading
Multithreading Multithreading
Multithreading
 
Multithreaded processors ppt
Multithreaded processors pptMultithreaded processors ppt
Multithreaded processors ppt
 
Thread
ThreadThread
Thread
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
P-Threads
P-ThreadsP-Threads
P-Threads
 
Thread management
Thread management Thread management
Thread management
 
Lecture 9 -_pthreads-linux_threads
Lecture 9 -_pthreads-linux_threadsLecture 9 -_pthreads-linux_threads
Lecture 9 -_pthreads-linux_threads
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
Threads
ThreadsThreads
Threads
 
4 threads
4 threads4 threads
4 threads
 
OS_Ch5
OS_Ch5OS_Ch5
OS_Ch5
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
 
Pthread Library
Pthread LibraryPthread Library
Pthread Library
 

Similar to Server Architecture Models: Fork-Exec, Pre-Forking, Thread Pool & Event-Driven

Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfHarika Pudugosula
 
Java concurrency - Thread pools
Java concurrency - Thread poolsJava concurrency - Thread pools
Java concurrency - Thread poolsmaksym220889
 
Threads in java, Multitasking and Multithreading
Threads in java, Multitasking and MultithreadingThreads in java, Multitasking and Multithreading
Threads in java, Multitasking and Multithreadingssusere538f7
 
chapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.pptchapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.pptaakarshsiwani1
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptxbleh23
 
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docxCIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docxclarebernice
 
IEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualIEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualFreyrSCADA Embedded Solution
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.pptshreesha16
 
Multithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfMultithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfHarika Pudugosula
 
Multithreaded_Programming_in_Python.pdf
Multithreaded_Programming_in_Python.pdfMultithreaded_Programming_in_Python.pdf
Multithreaded_Programming_in_Python.pdfgiridharsripathi
 
OOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptxOOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptxArulmozhivarman8
 

Similar to Server Architecture Models: Fork-Exec, Pre-Forking, Thread Pool & Event-Driven (20)

Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
 
Java concurrency - Thread pools
Java concurrency - Thread poolsJava concurrency - Thread pools
Java concurrency - Thread pools
 
Threads in java, Multitasking and Multithreading
Threads in java, Multitasking and MultithreadingThreads in java, Multitasking and Multithreading
Threads in java, Multitasking and Multithreading
 
Ch04 threads
Ch04 threadsCh04 threads
Ch04 threads
 
chapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.pptchapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.ppt
 
Chapter 6 os
Chapter 6 osChapter 6 os
Chapter 6 os
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 
Threads
ThreadsThreads
Threads
 
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docxCIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
CIS3110 Winter 2016CIS3110 (Operating Systems) Assig.docx
 
Threads
ThreadsThreads
Threads
 
Pthread
PthreadPthread
Pthread
 
Threading.pptx
Threading.pptxThreading.pptx
Threading.pptx
 
Threads
ThreadsThreads
Threads
 
MULTI THREADING.pptx
MULTI THREADING.pptxMULTI THREADING.pptx
MULTI THREADING.pptx
 
IEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualIEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manual
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.ppt
 
Multithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfMultithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdf
 
Multithreaded_Programming_in_Python.pdf
Multithreaded_Programming_in_Python.pdfMultithreaded_Programming_in_Python.pdf
Multithreaded_Programming_in_Python.pdf
 
OOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptxOOPS object oriented programming UNIT-4.pptx
OOPS object oriented programming UNIT-4.pptx
 
Topic 4- processes.pptx
Topic 4- processes.pptxTopic 4- processes.pptx
Topic 4- processes.pptx
 

More from rutu_taware (6)

Sa
SaSa
Sa
 
Sa
SaSa
Sa
 
Sa
SaSa
Sa
 
Sa
SaSa
Sa
 
Sa
SaSa
Sa
 
Sa
SaSa
Sa
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

Server Architecture Models: Fork-Exec, Pre-Forking, Thread Pool & Event-Driven

  • 1. Server Architecture Models Operating Systems Hebrew University Spring 2004
  • 4. Drawbacks 1. This multiprocessing architecture is useful if the handling of the client request takes some time or a session state has to be kept by the (child) server 2. HTTP, however, is a stateless protocol. No session information needs to be kept by the server 3. An HTTP server based on that architecture would be inefficient – The master server would have to create a process for each HTTP connection, which would handle this one connection only and then die – While the master server creates a process it cannot accept incoming requests – a bottleneck for the entire server.
  • 5. Pre-Forking Model – The leader-followers pattern The preforking architecture is based on a pool of tasks (processes or threads) which are playing 3 different roles: •wait for requests (listener) •process a request (worker) •queue in and wait to become the listener (idle worker) •The listener is the leader, the idle workers are the followers
  • 6. Win32/WinNt MPM • Uses threads (a lot more performant than Win processes) – The number of threads is fixed, since idle threads impose almost no performance issue • There are two Windows processes in this multitasking architecture: – At restart, the master process creates the child process – The worker process (child server process) contains the threads which handle the requests, – while the supervisor process (master process) makes sure that the worker process works correctly – For connection distribution to the workers a job queue is used
  • 7. Win32/WinNt MPM cont. • The master-child connection is done via events – master to child: shutdown, restart – child to master: need restart, error that requires shutdown • Worker process’ threads: – master thread – starts one or multiple listeners – listener(s) thread(s) – accept requests and put into the job queue – worker threads – read from the queue and handle requests (by calling some routine)
  • 9. MPM for Linux/Unix • Combine a multiprocessing and a multithreading model: – a variable number of processes, which include a fixed number of threads – pre-forking model on process level and job queue model on thread level – each child process incorporates a listener thread • The master server creates the child process, which starts a starter thread that set up all worker threads and a single listener thread
  • 10. MPM for Linux/Unix cont. • Within each child process, the communication between the listener and all worker threads is organized with two queues: – the job queue – the idle queue • Advantages of this approach are that it combines: – the stability of multiprocessing – the high performance of multithreading
  • 12. Thread Pool 1. Create a number of threads at process startup and place them into a pool where they sit and wait for work. • e.g. for multithreading a web server. 2. A thread from the pool is activated on the request, and it returns to the pool on completion. 3. Benefits of thread pool: – Faster service – Limitation on the number of threads, according to the need. 4. Thread-pool-architecture allows dynamic adjustment pool size.
  • 13. Thread Pool Model for Ex4 • From the exercise definition: Build a multithreaded server. The main thread will handle user input, second thread will handle load balancing between computation threads, additional three threads will be used to compute prime numbers, and the last thread will handle all output.
  • 14. Thread Pool Model for Ex4 user output thread Main thread computation thread balancing thread input computation thread computation thread
  • 15. thread creation int pthread_create(pthread_t *thread, pthread_attr_t *attr, void* (*start_routine)(void*), void *arg); thread – pointer to the new thread attr – the new thread attributes, usually NULL (i.e. system thread that we can do ‘join’ on it = wait to his end). start_routine – pointer to the function that is the thread code, the return value of that function is the end value of the thread arg – parameter for the start_routine function
  • 16. mutex locks int pthread_mutex_lock(pthread_mutex_t *mutex); – blocks until the mutex is free, and than locks it int pthread_mutex_trylock(pthread_mutex_t *mutex); – fails if the mutex is already locked, otherwise – locks it int pthread_mutex_unlock(pthread_mutex_t *mutex); – frees (unlocks) the mutex
  • 17. Event-driven • The main program creates acceptors. • Each acceptor creates event-handler for each event it is interested in, and the handler registers for this event. • The main program listens for events. • When event occurs, the appropriate acceptor is notified, notify the handler, which handle the event.
  • 18. Event-driven cont. • Advantages: – services can run independently – integrating new services is easy – a programmer can do his own ‘task management’ and save context switching (context is saved in the data structure) • Drawbacks: – resource management problems if requests arrive faster than they are processed – big overhead for system with short-duration services – harder to implement than other models
  • 19. References Apache Modeling Portal http://apache.hpi.uni-potsdam.de/document/4_3Multitasking_server.html Efficient Architectures for object-oriented component based Middleware http://www.stal.de