2 service and configuration design dimensions
Network Programming comprehensively balances complexity, security, and robustness, while making trade-offs in terms of time and space.
Complexity:
Single Service, stateless connection (HTTP)
Status hold (SMTP)
Thread Pool/(Oracle connection mode)
Listener Manager (inetd manages FTP and Telnet connections)
Security:
1) Multithreading
1. multithreading may cause problems: multiple threads share the same system resources and distribute different threads for connections of two users with different permissions, the two threads share the same file handle, which may pose a threat to system security.
2) Dynamic Connection Library
2. The same applies to dynamic database connection. Each process maps to the same database file. If a user modifies the database file. In this way, other users are also affected. A typical operation is a Trojan horse ". (Trojan horses)
Robustness
1) dynamic configuration. 24*7 uninterrupted operation. (Dynamic service reconfiguration ). An additional Configuration Manager is required to broadcast configuration update events.
2) load balancing.
Time:
1) running time:
Multi-thread: Shared data pages, effectively avoiding violent memory paging.
Thread/process pool: Reduces the time consumed for Thread/process creation and destruction.
2) space:
Thread Pool: a large amount of process space is used.
Dynamic Connection Library: reduces memory usage.
Simplest network server:
Several efficient network server models:
1. Multi-Service (multiservice servers) servers
Listen supports multiple ports, and select Monitors multiple socket handles. After the Select Operation, the event is sent to the appropriate process. Inetd is a typical example.
The multi-service model separates the TCP handshake process from the business logic. BenefitsCodeMaintenance.
2. multi-thread pool Server
Use local IPC to pass socket handle from the listening process to the session process. To implement a process to process multiple socket handle. Each thread uses ace_tp_reactor: handle_events () to process events on socket handle in a multi-threaded model.
The process pool and thread pool (Standing servers) are implemented through local IPC. Apue 2th edition 17.4. Passing file descriptors describes how to transfer handles between processes through the IPC Mechanism.