This book mainly shares the author's experience in implementing multi-thread and network programming in the company's internal distributed service system, and introduces C ++
Many of the design decisions in this book are made in this application scenario. This book does not elaborate on the Design of Distributed systems. It only lists the challenges of distributed systems and their impact on programming (Server programming) in Chapter 9th, such as reliability and maintainability.
The cross-reference relationship diagram of each chapter is as follows (no reference count is calculated). Chapter 1 is the preface and the letter section is the appendix. It can be seen that chapter 1 "distributed system engineering practices" is the most cited chapter, and many content in the book is paving the way for it.
The title of this book was originally intended to be "Linux C ++
Multi-threaded system programming ". In writing, it is found that, unlike other Unix/Linux programming books, this book has a clear application scenario, so it can cut a lot of content and highlight the key. According to Shannon's definition, "information" is "reducing uncertainty". The information contained in this book is reducing uncertainty in the selection of programming facilities (facilities), allowing readers to concentrate on solving essential problems. This is not a comprehensive book, so the final title is not "system programming. For example:
· This book does not take a long time to talk about signal. Instead, it explains in section 4.10 that multithreading programs should not use signal as IPC. In addition, the unique signalfd usage in Linux is provided in the muduo-protorpc example to avoid the traditional signal
Handler's common traps. Section 4.4 indicates that the thread should not be terminated from the outside, so you do not have to go into the pthreads cancellation point.
· This book does not introduce daemon processes because the parent process of such processes is INIT (1), which is not easy to monitor and manage (section 9.8 ). For ease of management, the business process should not fork (). Multi-threaded programs are also recommended not to fork () (Section 4.9 ).
· This book only focuses on Linux without considering portability. It is recommended to use Linux's proprietary gettid () system call as the thread ID (section 4.3), rather than pthread_self (); muduo uses timerfd to implement high-precision timing, in addition, the C ++ standard library is used directly to manage the timer, rather than implementing the heap itself ).
· This book only talks about mutex and condition variable as the most basic thread synchronization means (Chapter 1). We recommend that you only use non-recursive mutex (Section 2.1.1 ), this is the opposite of some online article recommendations. In section 2.3 of this book, we do not even suggest using read/write locks and semaphores (semaphore), because one is easy to use and the other is not necessarily able to improve performance. With mutex and condition
Variable enables a variety of easier-to-use synchronization facilities, such as countdownlatch and blockingqueue.
· This book only describes BSD sockets as a means of inter-process communication and uses only TCP persistent connections (section 3.4 ). In this way, pipe, FIFO, and POSIX are cut down.
Message Queue, shared memory, streams, Unix domain socket, and so on, because they are only allowed to communicate with local processes and cannot be extended to multiple machines.
· In terms of network programming (chapter 7 and chapter 7), I only talk about the concurrent style of non-blocking Io combined with IO reuse (summarized as three and a half events ), this article also introduces the one
Loop per Thread ). This book does not talk about IPv6, because the service cluster of the world's largest company cannot use a private class A address (10.0.0.0/8 ).
· The network programming example in this book is no longer a simple echo service, but a network program with a format (So codec is introduced) and data exchange between multiple connections, which is closer to the business scenario, it also explains how to avoid common traps in TCP network programming. In addition, the sample code provides a slightly more complex program, such as distributed word count and multi-machine median calculation.
· In terms of C ++, this book does not introduce the "advanced" Technology of dynamic link library hot update, but rather shows that in Distributed Systems, for ease of deployment, all libraries should be compiled from the source code and linked to the main program as a standalone executable file to reduce dependencies on the runtime environment (Chapter 1 ). Chapter 2 also discusses the interface design between libraries and applications.
For more information, see the related webpage: chenshuo.com/book, including the sample chapter; errata; url.pdf.
Book excerpt
Section 6.6.2