正在加载图片...
Optimizing stateless servers Optimizing stateless servers Consider a connectionless server for file Table of information about files clients are using We find hash(IP addr, port) Overhead of opening and closing file Clients may read only a dozen bytes in each Buffer for file x Clients tend to read files sequentially starting at byte 512 To optimize the performance Offset: 1024 Maintain a small table of file information Buffer for file y State information starting a Optimizing stateless servers Four basic types of servers Improve performance without any penalty? Iterative connectionless Even a small amount of information can cause a a Iterative connection-oriented server to perform badly when machines, client a Concurrent connectionless programs, or networks fail Frequent crashes can cause one client to dominate a Concurrent connection-oriented table by filling it with entries that will never b Iterative servers suffice only for the trivial application protocols A programmer must be extremely careful when Iterative servers work best with simple optimizing a stateless server services accessed by a connectionless access protocol Iterative connection-oriented Binding to a well-known address server algorithm by using INADDR_ANy Creating a socket and bind to the well-know s binduses structure sockaddr in address for the service being offered Place the socket in passive mode, making it ready Selecting a specific IP address at which a for use by a server server will accept connections can cause Accept the next connection request from the difficult ocket, and obtain a new socket for the connection. repeatedly receive a request from the clien especially for gateways(routers) ormulate a response, and send a reply back to the a Special constant: INADDR_ANy client according to application-protocol. Wildcard address When finished with a particular client, close the a Servers use INADDR ANy instead a connection and return to step 3 to accept a new onnection specific IP address2 哈工大计算机学院 李全龙 Network Application Development Server Software Design 7 Optimizing stateless servers „ Consider a connectionless server for file reading „ We find: „ Overhead of opening and closing file „ Clients may read only a dozen bytes in each request „ Clients tend to read files sequentially „ To optimize the performance „ Maintain a small table of file information „ State information 哈工大计算机学院 李全龙 Network Application Development Server Software Design 8 Optimizing stateless servers Filename:X Offset:512 Buffer pointer: Filename:Y Offset:1024 Buffer pointer: Table of information about files clients are using hash(IP addr,port) Buffer for file X starting at byte 512 Buffer for file Y starting at byte 1024 哈工大计算机学院 李全龙 Network Application Development Server Software Design 9 Optimizing stateless servers „ Improve performance without any penalty? „ Even a small amount of information can cause a server to perform badly when machines, client programs, or networks fail „ Frequent crashes can cause one client to dominate the table by filling it with entries that will never be used „ A programmer must be extremely careful when optimizing a stateless server 哈工大计算机学院 李全龙 Network Application Development Server Software Design 10 Four basic types of servers „ Iterative connectionless „ Iterative connection-oriented „ Concurrent connectionless „ Concurrent connection-oriented „ Iterative servers suffice only for the trivial application protocols „ Iterative servers work best with simple services accessed by a connectionless access protocol 哈工大计算机学院 李全龙 Network Application Development Server Software Design 11 Iterative connection-oriented server algorithm 1. Creating a socket and bind to the well-known address for the service being offered. 2. Place the socket in passive mode, making it ready for use by a server. 3. Accept the next connection request from the socket, and obtain a new socket for the connection. 4. Repeatedly receive a request from the client, formulate a response, and send a reply back to the client according to application-protocol. 5. When finished with a particular client, close the connection and return to step 3 to accept a new connection. 哈工大计算机学院 李全龙 Network Application Development Server Software Design 12 Binding to a well-known address by using INADDR_ANY „ bind uses structure sockaddr_in „ Selecting a specific IP address at which a server will accept connections can cause difficulty „ especially for gateways (routers) „ Special constant: INADDR_ANY „ Wildcard address „ Servers use INADDR_ANY instead a specific IP address
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有