The MyServer threads model explained
Giuseppe Scrivanogscrivano@gnu.org
Abstract
In the era of Internet and Web 2.0, web servers have the impor-tant role to serve information as quickly as possible. In the Web 1.0era, web contents were mainly static and rarely modified; AJAX websites now introduce many additional requests for web contents to beupdated dynamically.In this scenario there is need for web servers able to serve manyclients at the same time. Threads are the ideal choice to handle manyrequests: they don’t need much resources and share the same memoryamong them.
1 Introduction
MyServer is a web server based on a multithreaded architecture; many con-nections can be served at the same time by the same process.Other common architectures are the single threaded server, where a pro-cess can handle only one connection at time and the multi-processes server,where a new process is created to handle each request. A process needsmany resources to be allocated. Within UNIX-like operating systems this isdone by duplicating the calling process, through a mechanism called “fork”.Some modern implementations allow the child process to share memory withthe parent process until one of them modifies something (copy-on-write).Although all these are improvements to the original mechanism, creating aprocess is still a slow operation.Aside from processes there are threads or lightweight processes, that doalmost the same things that processes do, with the advantage of being fasterto create than a process. Threads are not only faster to create, but they usefewer resources than processes; and every thread needs to save only its stackand CPU registers status information.Threads of the same process share the same memory and descriptors table,as well as access to any opened resource (files, sockets, etc...). The cost of 1
Leave a Comment