Performance Optimization of server programs in Linux

Source: Internet
Author: User

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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.