In the recommendation of seniors, I spent about half a month to learn the Zhang teacher's "Linux High Performance Server Programming" book. Read this book, feel this book in the breadth of knowledge is already very sufficient, on the network protocol and programming aspects of the basic knowledge stack are explained, the language is relatively easy to understand, is a certain network foundation also want to continue in-depth study of students good book, but because space is limited, for some of the knowledge point of the explanation not in depth.
The book is divided into three parts: the 1th Chapter to the 4th chapter mainly discusses the commonly used TCP/IP protocol, and its communication process, for the subsequent network programming lay a good foundation; 5th to 15th Chapter 11 covers the main aspects of high-performance servers, which are divided into four small parts, API introduction, High-performance server frameworks, I/O units, and logical units; Chapters 16th through 17th explain how to optimize and detect server performance from a system perspective.
I will summarize all the key knowledge of this book by chapter.
The first chapter TCP/IP protocol family
The TCP/IP protocol family is the most widely used and the most important protocol system in the world, which is from the low to the lowest: Data link layer, network layer, Transport layer and application layer.
There are two commonly used protocols on the data Link layer, the ARP protocol and the RARP protocol, where the RARP protocol is generally only used for diskless workstations on the network, because there is no storage media, the diskless workstation cannot remember its IP address, so it can use the physical address on the network card to query its IP address to the server.
The ARP protocol is the most important, he can realize any network layer address to any physical address conversion, but generally only the IP address to MAC address conversion. It works because the host broadcasts an ARP request to its own network, which contains the network address of the target machine, and when the remaining host receives the request, only the requested target Master has responded to an ARP response, which contains its own physical address.
ARP Request/Reply message content Total 28 bytes, plus Ethernet header 14 bytes and tail CRC4 bytes, a total of 46 bytes. However, there is a minimum of 64 bytes of packet spread over the Ethernet, so you need to fill 0 at the end of the frame.
Where the hardware type value is 1, which represents the MAC address, the protocol type represents the protocol address type to be mapped, the value is 0x0800, the IP address, the Action field is the OP field has four values, 1 is the ARP request, the 2-bit ARP answer, 3 is the RARP request, and 4 is the rapr answer.
The network layer is a connecting layer in the whole TCP/IP protocol stack, which realizes the routing and forwarding of packets. In the WAN, the communication between the two hosts is generally not directly connected, but through a number of intermediate routers connected, so the network layer of the task is to choose these intermediate points to determine the communication path, at the same time, the network layer is transparent to the upper layers, that is, in the transport layer, the communication is directly connected to each other.
On the network layer, the most important protocol is the IP protocol, which is explained in detail in the second chapter. In addition, there is the ICMP protocol, he is an important supplement of IP protocol, mainly used for network connection detection, divided into two categories, error messages and query packets. Its header includes 1-byte type, 1-byte code, 2-byte inspection and the rest as message content, depending on the header.
The transport layer encapsulates an end-to-end logical communication link for the application, consisting mainly of three protocols: TCP, UDP, and SCTP, and generally we only discuss the first two. The TCP protocol provides the application layer with reliable, connection-oriented and stream-based services, and the TCP protocol uses a time-out retransmission, data validation, and so on to ensure that packets are sent to the destination correctly. TCP is stream-based, stream-based data has no boundary limit, it flows from one segment of communication to the other, the sending side can write data to the data stream byte by bit, and the receiving end can read it byte by bit. While the UDP protocol is the opposite, he is a non-connected, unreliable and datagram-based services, which means that the UDP protocol does not guarantee that the data from the sender to the destination correctly, if lost in the middle, UDP is simply to notify the application to send the failure, therefore, Applications that use UDP often have to handle the logic of data validation, time-out retransmission, and so on. UDP is a datagram-based service, and each UDP datagram has a length, and the receiving end must read all of its contents one at a time in the smallest unit of that length, otherwise the data will be truncated.
The logic of the application should be processed on the application tier, the remaining three tiers are implemented in the kernel space, and the application layer needs to be implemented in user space. There are many protocols to the application layer, such as Telnet, HTTP, DNS, OSPF, and so on.
DNS is a set of distributed domain Name System, we usually use the domain name to access the machine, in fact, the essence is to access the other host on the network corresponding to the unique IP address, but why we use the domain name can also be accessed. We enter the domain name at the same time, the main opportunity to send a DNS request message to the DNS server, meaning to ask the other side of the domain corresponding IP address is how much, and the DNS server is a large number of machine names and IP address mapping, and is dynamically updated, so the host know the destination host IP address. For DNS resolution, a total of two query methods, iterative query and recursive query, the difference is: The iterative query is host A to Server B to initiate a DNS query request, but Server B does not know the IP address of the domain name, then he returned to host a another server C IP address, Let host a continue to Server C query, that is, in this query mode, the server is irresponsible, is initiated by the host query request, and recursive query, if Server B is a recursive query mode, then for host a query request, it will be discretionary agent, if you do not know the destination host IP address, It continues to query the parent DNS server until the IP address is found and returns it to host A. In Linux, the address of the DNS server is in the/etc/resolv.conf file.
Linux High Performance Server Programming learning Summary (i)--TCP/IP protocol family