Design of a memory pool for high concurrent server design

Source: Internet
Author: User
Tags int size resource

Different business, design is not the same, but at least some common pursuit, such as performance.

Do server development for many years, and sometimes people ask, what is the server performance? What do you spell among the various servers?

The simple answer is QPS, concurrent numbers, but sometimes it may not be right to think about it.

QPS and concurrent numbers are for the same business, the same server can withstand different pressures.

Performance, perhaps to make a vulgar point of analogy:

The server is a ship, performance is the capacity of the ship, open speed, the line is stable.

The use of the province's province. can use memory do not use IO, CPU can use less, the same qps,cpu and memory with less performance than the use of more good, the same, QPS run more points than

The performance of the small run is better, even if the use of a little CPU and memory.

What is the guarantee of performance?

Efficient event model, simple and straightforward business architecture, unified and stable resource management, plus skilled personnel.

Let me start with the resources.

Resources are mostly IO-related, if you look at my previous article, will not be unfamiliar to the connection pool, yes, the connection is a system of IO resources, the next look at another IO resource: memory.

If you've seen the code of a server like Apache, Nginx, or want to start with, then most of it should begin with memory management.

and server performance is closely related to the design of the memory pool is also the pursuit of fast and stable, the life cycle generally has the following three kinds:

Global: The overall memory that holds global information for the entire process.

Conn: information for each connection, from connection generation to shutdown.

Busi: Business-related information, accompanied by the creation of each business to the end

The following defines a simple memory pool:

typedef struct YUMEI_MEM_BUF_S 

yumei_mem_buf_t;  
typedef struct YUMEI_MEM_POOL_S yumei_mem_pool_t;  
      
struct yumei_mem_buf_s  
{  
    int                          size;  
    Char                        *pos;  
    Char                        *data;  
    yumei_mem_pool_t            *pool;  
};  
      
struct yumei_mem_pool_s  
{  
    int                          size;  
    Char                        *data;  
    Char                        *last;  
    yumei_mem_pool_t            *next;  
    yumei_mem_pool_t            *current;  
};  
      
yumei_mem_pool_t* yumei_mem_pool_create (int block_size, int block_num);  
int Yumei_mem_pool_free (yumei_mem_pool_t  *pool);  
yumei_mem_buf_t* Yumei_mem_malloc (yumei_mem_pool_t   *pool, int size);  
int Yumei_mem_buf_free (yumei_mem_buf_t *buf);

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.