This problem can be said to be big, small, and short. It is basically a summary of your own experience.
Grandpa Gao said, "premature optimization is the source of all evil". It is impossible for developers to think about optimization from the very beginning. They should consider the global issue, consider the advantages and disadvantages from various perspectives, and make
The design is in line with the overall interests, and then we will consider how to optimize it.
Optimization is to improve the performance under the existing design architecture. If you have designed a low-performance architecture at the beginning and cannot meet your needs, you can only roll back and optimize it.
Experience is summarized as follows:
(1) Replacing round robin with event-driven
(2) reduce system calls
(3) use high-performance system APIs such as zero copy and epoll
(4) use Asynchronous synchronization instead of synchronization as much as possible, divide a task into multiple threads or processes for processing, and give full play to the advantages of multi-core pipeline operations
(5) Reasonably set and use various caches
(6) pool mechanism and pre-allocation
(7) Delayed allocation, similar to fork's copy on write Mechanism
(8) As far as possible no lock design, double check, spin lock, read/write lock
(9) reduce memory invalid operations (MEM series), lockless ring buffer, using writev/readv
(10) set the size of the TCP sending/receiving buffer
(11) minimize the generation of temporary objects in C ++
Do not abuse the string + operation
PASS Parameters to avoid passing values
Consideration of vtable costs
Use Error Codes instead of exceptions
The length of a String constant must be sizeof, instead of strlen.