1. Multi-process or multithreaded model
multi-Process Server : APACHE,NGINX,LIGHTTPD and other servers are multi-process models, divided into master process and Woker process
advantages of multi-process : Greater fault tolerance-a process hangs without causing the entire system to crash, better multicore scalability-the use of processes isolates many kernel resources (such as address space, page tables, open files), and is more scalable on multicore systems than multithreaded programs.
multi-threaded server : Tomcat,netty and other servers are multithreaded models, divided into network IO threads and business threads.
Multi-Threading Benefits : Increased responsiveness, allowing IO and " compute " to overlap each other, reducing latency. Although multi-threading does not improve absolute performance, it can improve average response performance.
2. Server-side network model
Linux: Select/poll/epoll model
Java:: Bio/nio model
3. Synchronous/Asynchronous model
Synchronization: A typical bio model where each thread processes a single connected network data read-write and business logic
Async:: Typical NIO model, a single thread can manage multiple network connections, network event-driven
synchronous and asynchronous mechanisms of how messages are notified, rather than the mechanism of handling messages. In other words, in the case of synchronization, it is up to the handler to wait for the message to be triggered by itself, while the asynchronous case is triggered by the trigger mechanism to notify the person who processed the message.
blocking and non-blocking are good differences, so-called blocking is when the system call is complete, and the blocked process is in the sleep state. Non-blocking refers to the immediate return of a system call regardless of completion, and does not cause the process to hang.
three levels of Asynchrony :
Asynchronous socket data Transfer (NIO)
Asynchronous HTTP request (Jetty Continuation,servlet 3)
Async of work business logic (future, callable, Runnable)
4. Inter-process communication and inter-thread communication
In a multithreaded concurrency environment, it is essentially the two problems: how to communicate between threads and how threads are synchronized.
Linux interprocess communication means : FIFO, POSIX Message Queuing, shared memory, signal (signals), Pipeline (pipe), socket (socket), etc.
Linux Multi-threaded synchronization primitives : mutexes (mutexes), condition variables (condition variable), read
Write Lock (Reader-writer lock), file Lock (Record locking), Semaphore (Semaphore), etc.
Multithreading synchronization and communication mechanisms available on the Java platform
Java Multithreading Communication and synchronization : wait/notify mechanism, synchronized keyword, lock lock, condition condition variable, semaphore semaphore, Atomic Atomic class, Cyclicbarrier, Countdownlatch, wait.
5. Message Protocol Design
TLV encoding and its variants : Protobuf/thrift/asnber all belong to this.
text stream encoding : Xml/json all belong to this.
Fixed structure encoding : TCP/IP is this.
Hybrid Structure Coding : Fixed structure + text protocol
6. Co-process Model
The process of a request is actually to consume a native thread, the benefit of the association is actually to do the actual reuse of threads, to avoid the wait and so on when the action still occupy the thread. Of course, the co-process only a large amount of circumstances in order to reflect the advantages, from each request a thread of the era is not as many requests for common threads, the full use of CPU capacity, to avoid consumption in unnecessary switching.
The difference between a process and a thread is that the context switch of the association is done entirely in the user state, either by the language runtime or by the library. Thread context switching is done by the operating system.
The framework for implementing the Kilim,kilim in Java has the task of creating tasks, using the pause mechanism of the task, instead of Thread,kilim assuming the thread scheduling and the up and down switching actions, the task is much lighter than the native thread. And can better utilize the CPU. Kilim brings up the increase in thread utilization, but also consumes more memory in the case of Kilim, because the task context information is saved in the JVM heap.
Server-side development technology