Server development experience and development experience

Source: Internet
Author: User

Server development experience and development experience

During this time, I developed a game server in the company. I recorded some experiences in the development process, and I will also have some experiences in the future.

1. timed refresh mechanism. The server must have constant and timed refresh measures, such as the task system.

2. thread management and scheduling, generally using the thread pool Solution

3. In terms of memory, in order to improve performance, the memory pool is usually used instead of frequently allocating the memory dynamically.

4. data packet design, usually in the header + data packet body mode. When receiving data packets, first accept the packet header and then receive the remaining data according to the size described in the packet header;

Data packets are serialized (or serialized) in binary format to save space before being sent to the Buffer.

Google's protobuf is a good tool. Although it is not used in this project, it may be used in the future.

5. the queue is used. The server generally processes multiple threads. The queue logic can be clearly defined, which is often used in servers, such as data packet queues. In fact, in Windows, the idea of queue is also used to complete port IOCP.

6. Avoid competition. Place the processing of one Socket or connection in one thread. Do not allow multiple threads to process the same socket at the same time.

7. The log system and log system can also use the thread and queue ideas. You can consider using a cross-platform logstore, Log4cplus (Log4cxx), a powerful open-source C ++ logstore.

8. When asynchronous callback is used, sometimes the result to be processed on the server is more congested than it can be obtained immediately, such as database queries. In this case, asynchronous callback can be used to improve performance.

9. Timeout detection. Sometimes the client has been disconnected due to network reasons, but the server may not receive the signal for a long time. Therefore, timed timeout detection is necessary.

10. The application of state machines, such as user state machines and state machines, can make the logic clearer.

11. Use of design patterns, such as Singleton mode and observer mode.

 

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.