Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Write to programmers-Technical understanding and High concurrency Server Framework Design

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

From the perspective of an it technician who has been working for 19 years, sometimes I feel that programmers are very happy, a variety of open source products, a variety of development frameworks, the so-called architecture design is more about selection / selection; think about the past single-chip microcomputer, limited memory, low-frequency cpu, programming language to assembly-based, to the later cAccord programming. Increasingly pale hair, God knows what we have been through!

The pace of technological development has accompanied the growth of our generation, witnessing programmers' persistent pursuit of "reuse" in order to become "lazy". From the beginning of source-level reuse, to engineering / module reuse, to binary reuse, to today's service reuse, we have experienced from coding specification, to hierarchical architecture, and then to dynamic libraries, and then to follow the com/dcom developed by MS. Until SOA and all kinds of openRPC and micro services. He is already forty years old in a flash!

What is technology? In my opinion, the so-called technology is actually the ability to use handy tools to solve problems, and experience is gained from direct or indirect lessons after you have seen too much failure; experience can avoid making mistakes to a great extent, and the ability to solve problems requires that the best solution can always be found. Time settles down: I have never eaten pork, but I have seen all kinds of pigs running; the harvest is always negative, and most of the time you will think that most of the so-called popular or powerful technologies are actually new bottles of old wine.

In the past, some friends were keen on the design of high concurrency server architecture. in fact, this is a pseudo-proposition. The actual situation is: scenarios with more than 90% concurrency capability depend on business, and scale out should be considered more specifically. More specifically, scale out needs to consider business logic and data access, which is also the core of many Internet companies' solutions. For the other 10% of cases, if you explore a high concurrency framework from a purely technical architecture, the things you should consider include, but are not limited to:

1. Need to implement an AIO framework, if you need to cross-platform at least need to consider adapting to iocp/select/poll/epoll/kqueue/port and other platform-related implementation solutions, need to abstract the operation interface and event interface.

two。 You need to achieve an efficient thread-pool and minimize the probability of thread switching (at full load), so you may need a lock-free queue / or linked list, carefully designed mechanisms to avoid thread hunger or task delays

3. You need to design an efficient event handling mechanism, and it is recommended to use lock-free to implement the event queue; it is necessary to use thread-pool for task distribution, and it is best to consider the isolation of IO threads and task processing threads to prevent io detection from being untimely; and the type of thread (IO/ business) to which protocol parsing belongs also needs to be carefully considered. The best way is to let the thread pool retain the corresponding number of "emergency task" threads, and then let the IO/ business share the threads in the pool according to the rules.

4. The external programming interface of the framework needs to be standardized. It is recommended to encapsulate well and mask the socket handle so that external users can only manipulate the data. At least the operation interface and event interface need to be exposed.

A network framework has been implemented roughly in accordance with this idea, and the performance is OK. Http (64B) QPS is about 30% higher than nginx (nginx is about 850000 / s, self-developed framework is about 1.1 million / s), test environment 24C/64G, dual Gigabit network cards, and 2048 concurrent connections are full of negative CPUs. It has been used in commercial use.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report