⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 st.html

📁 快速开发
💻 HTML
📖 第 1 页 / 共 2 页
字号:
wait for network I/O events.  When a particular file descriptor is ready forI/O, the EDSM completes the corresponding basic step (usually by invoking ahandler function) and starts the next one.  This architecture usesnon-blocking system calls to perform asynchronous network I/O operations.For more details on non-blocking I/O see Stevens<A HREF=#refs3>[Reference 3]</A>.<P>To take advantage of hardware parallelism (real concurrency), multipleidentical processes may be created.  This is called Symmetric Multi-ProcessEDSM and is used, for example, in the Zeus Web Server(<A HREF=#refs4>[Reference 4]</A>).  To more efficiently multiplex disk I/O,special "helper" processes may be created.  This is called AsymmetricMulti-Process EDSM and was proposed for Web servers by Druscheland others <A HREF=#refs5>[Reference 5]</A>.<P>EDSM is probably the most scalable architecture for IAs.Because the number of simultaneous connections (virtual concurrency) iscompletely decoupled from the number of kernel execution vehicles (processes),this architecture has very good load scalability.  It requires only minimal user-level resources to create and maintain additional connection.<P>Like MP applications, Multi-Process EDSM has very good system scalabilitybecause no resources are shared among different processes and there is nosynchronization overhead.<P>Unfortunately, the EDSM architecture is monolithic rather than based on theconcept of threads, so new applications generally need to be implemented fromthe ground up.  In effect, the EDSM architecture simulates threads and theirstacks the hard way.<P><A NAME="ST"><H3>3. State Threads Library</H3></A><P>The State Threads library combines the advantages of all of the abovearchitectures.  The interface preserves the programming simplicity of threadabstraction, allowing each simultaneous connection to be treated as a separatethread of execution within a single process. The underlying implementation isclose to the EDSM architecture as the state of each particular concurrentsession is saved in a separate memory segment.<P><H4>3.1 State Changes and Scheduling</H4><P>The state of each concurrent session includes its stack environment (stack pointer, program counter, CPU registers) and its stack.  Conceptually, a thread context switch can be viewed as a process changing its state.  There are no kernel entities involved other than processes.  Unlike other general-purpose threading libraries, the State Threads libraryis fully deterministic.  The thread context switch (process state change) canonly happen in a well-known set of functions (at I/O points or at explicitsynchronization points).  As a result, process-specific global data does nothave to be protected by mutual exclusion locks in most cases.  The entireapplication is free to use all the static variables and non-reentrant libraryfunctions it wants, greatly simplifying programming and debugging whileincreasing performance.  This is somewhat similar to a <I>co-routine</I> model(co-operatively multitasked threads), except that no explicit yield is needed--sooner or later, a thread performs a blocking I/O operation and thus surrenderscontrol.  All threads of execution (simultaneous connections) have thesame priority, so scheduling is non-preemptive, like in the EDSM architecture.Because IAs are data-driven (processing is limited by the size of network buffers and data arrival rates), scheduling is non-time-slicing.<P>Only two types of external events are handled by the library'sscheduler, because only these events can be detected by<TT>select(2)</TT> or <TT>poll(2)</TT>: I/O events (a file descriptor is readyfor I/O) and time events(some timeout has expired).  However, other types of events (such asa signal sent to a process) can also be handled by converting them to I/Oevents.  For example, a signal handling function can perform a write to a pipe(<TT>write(2)</TT> is reentrant/asynchronous-safe), thus converting a signalevent to an I/O event.<P>To take advantage of hardware parallelism, as in the EDSM architecture,multiple processes can be created in either a symmetric or asymmetric manner.Process management is not in the library's scope but instead is left up to theapplication.<P>There are several general-purpose threading libraries that implement a<I>many-to-one</I> model (many user-level threads to one kernel executionvehicle), using the same basic techniques as the State Threads library (non-blocking I/O, event-driven scheduler, and so on).  For an example, see GNUPortable Threads (<A HREF=#refs6>[Reference 6]</A>).  Because they aregeneral-purpose, these libraries have different objectives than the State Threads library.  The State Threads library is <I>not</I> a general-purposethreading library,but rather an application library that targets only certain types ofapplications (IAs) in order to achieve the highest possible performance andscalability for those applications.<P><H4>3.2 Scalability</H4><P>State threads are very lightweight user-level entities, and therefore creatingand maintaining user connections requires minimal resources.  An applicationusing the State Threads library scales very well with the increasing numberof connections.<P>On multiprocessor systems an application should create multiple processesto take advantage of hardware parallelism.  Using multiple separate processesis the <I>only</I> way to achieve the highest possible system scalability.This is because duplicating per-process resources is the only way to avoidsignificant synchronization overhead on multiprocessor systems.  Creatingseparate UNIX processes naturally offers resource duplication.  Again,as in the EDSM architecture, there is no connection between the number ofsimultaneous connections (which may be very large and changes within a widerange) and the number of kernel entities (which is usually small and constant).In other words, the State Threads library makes it possible to multiplex alarge number of simultaneous connections onto a much smaller number ofseparate processes, thus allowing an application to scale well with boththe load and system size.<P><H4>3.3 Performance</H4><P>Performance is one of the library's main objectives.  The State Threadslibrary is implemented to minimize the number of system calls and to make thread creation and context switching as fast as possible.For example, per-thread signal mask does not exist (unlikePOSIX threads), so there is no need to save and restore a process'ssignal mask on every thread context switch. This eliminates two systemcalls per context switch.  Signal events can be handled much moreefficiently by converting them to I/O events (see above).<P><H4>3.4 Portability</H4><P>The library uses the same general, underlying concepts as the EDSM architecture, including non-blocking I/O, file descriptors, and I/O multiplexing.  These concepts are available in some form on most UNIX platforms, making the library very portable across many flavors of UNIX.  There are only a few platform-dependent sections in thesource.<P><H4>3.5 State Threads and NSPR</H4><P>The State Threads library is a derivative of the Netscape Portable Runtime library (NSPR) <A HREF=#refs7>[Reference 7]</A>. The primary goal of NSPR is to provide a platform-independent layer for system facilities, where system facilities include threads, thread synchronization, and I/O.Performance and scalability are not the main concern of NSPR.  The State Threads library addresses performance and scalability while remaining much smaller than NSPR.  It is contained in 8 source files as opposed to more than 400, but provides all the functionality that is needed to write efficient IAs on UNIX-like platforms.<P><TABLE CELLPADDING=3><TR><TD></TD><TH>NSPR</TH><TH>State Threads</TH></TR><TR><TD><B>Lines of code</B></TD><TD ALIGN=RIGHT>~150,000</TD><TD ALIGN=RIGHT>~3000</TD></TR><TR><TD><B>Dynamic library size&nbsp;&nbsp;<BR>(debug version)</B></TD><TD></TD><TD></TD></TR><TR><TD>IRIX</TD><TD ALIGN=RIGHT>~700 KB</TD><TD ALIGN=RIGHT>~60 KB</TD></TR><TR><TD>Linux</TD><TD ALIGN=RIGHT>~900 KB</TD><TD ALIGN=RIGHT>~70 KB</TD></TR></TABLE><P><H3>Conclusion</H3><P>State Threads is an application library which provides a foundation forwriting <A HREF=#IA>Internet Applications</A>.  To summarize, it has thefollowing <I>advantages</I>:<P><UL><LI>It allows the design of fast and highly scalable applications.  Anapplication will scale well with both load and number of CPUs.<P><LI>It greatly simplifies application programming and debugging because, as arule, no mutual exclusion locking is necessary and the entire application isfree to use static variables and non-reentrant library functions.</UL><P>The library's main <I>limitation</I>:<P><UL><LI>All I/O operations on sockets must use the State Thread library's I/Ofunctions because only those functions perform thread scheduling and preventthe application's processes from blocking.</UL><P><H3>References</H3><OL><A NAME="refs1"><LI> Apache Software Foundation,<A HREF="http://www.apache.org">http://www.apache.org</A>.<A NAME="refs2"><LI> Douglas E. Comer, David L. Stevens, <I>Internetworking With TCP/IP,Vol. III: Client-Server Programming And Applications</I>, Second Edition,Ch. 8, 12.<A NAME="refs3"><LI> W. Richard Stevens, <I>UNIX Network Programming</I>, Second Edition,Vol. 1, Ch. 15.<A NAME="refs4"><LI> Zeus Technology Limited,<A HREF="http://www.zeus.co.uk/">http://www.zeus.co.uk</A>.<A NAME="refs5"><LI> Peter Druschel, Vivek S. Pai, Willy Zwaenepoel,<A HREF="http://www.cs.rice.edu/~druschel/usenix99flash.ps.gz">Flash: An Efficient and Portable Web Server</A>. In <I>Proceedings of theUSENIX 1999 Annual Technical Conference</I>, Monterey, CA, June 1999.<A NAME="refs6"><LI> GNU Portable Threads,<A HREF="http://www.gnu.org/software/pth/">http://www.gnu.org/software/pth/</A>.<A NAME="refs7"><LI> Netscape Portable Runtime,<A HREF="http://www.mozilla.org/docs/refList/refNSPR/">http://www.mozilla.org/docs/refList/refNSPR/</A>.</OL><H3>Other resources covering various architectural issues in IAs</H3><OL START=8><LI> Dan Kegel, <I>The C10K problem</I>,<A HREF="http://www.kegel.com/c10k.html">http://www.kegel.com/c10k.html</A>.</LI><LI> James C. Hu, Douglas C. Schmidt, Irfan Pyarali, <I>JAWS: UnderstandingHigh Performance Web Systems</I>,<A HREF="http://www.cs.wustl.edu/~jxh/research/research.html">http://www.cs.wustl.edu/~jxh/research/research.html</A>.</LI></OL><P><HR><P><CENTER><FONT SIZE=-1>Portions created by SGI are Copyright &copy; 2000Silicon Graphics, Inc.  All rights reserved.</FONT></CENTER><P></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -