High performance server software development

zhaozj2021-02-16  59

This is the outline of a book being written, first sent, everyone mentioned opinions

High performance server software development

Brief introduction to this book:

Note that the high-performance server software design we discussed here is not a high-performance web program design in the usual sense, such as how to improve performance in J2EE, .NET framework, how to optimize ASP, PHP programs, or how to adjust Apache, IIS and other web servers for better performance, and more.

What is discussed here is the real-high performance from hardware to the underlying system, then the server design of the IO model, the application model, of course, as a family says, the same is equally misunderstood, biased, and ignorant, but if you blame me, please think carefully. The reason you accused, tell me your full advice after careful testing, I will thank this constructive accusation rather than others.

We face problems

There is already existed and will more and more network applications, including:

Instant chat server

FTP server

Internet-based media application

Large shopping site

Large portal

Online online game

When I actually use, we often encounter the following situation:

There are too many connections, the website is unable to access.

Unable to download files, or slow download speed

At the same time, the number of connections is greatly limited.

The site is very fragile, often being attacked such as such an attack.

For these, the usual solution is:

Increase hardware performance

Use server cluster and load balancing technology

Larger bandwidth

Do you really need?

Do we have careful thinking about our hardware itself, the limitations of operating systems, our application restrictions, where is the real bottleneck?

Let's take a look at the basic C / S network application.

Basic customer / server network application system:

The first class is non-connection-based system

Email, millions of grades, limited frequency, the same number of users is limited, the number of connections is limited

Instant chat, video or other online media

These systems have their own functional restrictions.

Connected static system

FTP download

HTTP Access

Connected dynamic system

Web site including dynamic pages, dynamic content and user unrelated

Including the user's concept and system of user-related data, there is often a background database.

Systems including business logic, such as electronic shopping sites, information ports, and recent popular online games.

What is the fundamental problem?

How to support more network connections, send / receive more data as possible with as few CPU time, memory occupation.

The fundamental construct from the bottom-up system includes:

1. Hardware facilities: including CPU computing power, hard drive, bid of network, throughput of network facilities.

2. Operating system: Operating system supports concurrent connection support and overhead, operating system IO overhead

3. Network application model: Basic network IO model, event notification mechanism

4. Application model: application system design of practical applications

5. Coding and implementation: The difference between good coding and poor implementation is very huge, here I propose some views that may have prejudice or extremes.

1, 2 Hardware facilities and operating systems overhead comparison.

We combine 1, 2 to compare:

Choose some of the basic hardware platforms below:

Typical laptop, P4M platform, 100M network card, 512M memory

Typical desktop, P4 platform, 100M network card, 512 memory

Typical server, Xeon platform, Gigabit NIC, 1G memory

Typical AMD64 bit server, Gigabit NIC, 1G memory

Software systems include:

Windows system:

Windows2000 Profession

Windows2000 Advance Server

Free UNIX class system:

Linux 2.4 kernel

Linux 2.6 kernel

FreeBSD5.1 kernel

The main performance assessment includes:

Basic call assessment of operating systems that affect server performance

l Assign / release memory overhead

l Create / abort threads / processes overhead

l Mutually exclusive overhead (overhead of context switching)

l Create / read and write over the memory image file

Basic assessment of network performance of operating system

l Create / release overhead

l Sack of the binding overhead of the text

l Establish a network connection overhead

l Send data / receive data throughput

l Delay and overhead of a standard HTTP request / response.

The initial results show that the Xeon system, the Xeon system clearly exceeds the usual notebook and desktop, and the AMD's 64-bit system has a very good performance performance under lower frequency (we still test 32 software). In terms of operating systems, all of the Unix systems exceed Windows platforms, while Linux2.6 kernels are best performed in each platform.

Design and evaluation of network IO models:

Basic concepts, how to notify the application to get data or send data on a socket.

The easiest way, using polling mechanisms to check the status of the socket, in many times, this way is the highest.

Polling mode specific application range:

Second, use each way to connect a thread, this way is feasible to determine

The operating system can use the number of threads

Operating system thread creation and overhead between thread switches. (Preliminary test shows that Linux2.6 kernel can create more than 5,000 threads per second)

Two basic message triggering:

Condition trigger and edge trigger

Common SELECT is the condition trigger.

WINDOW platform:

Includes common SELECT models

Event SELECT model

The IO completes the port model, which is actually a ribbon trigger.

Linux platform

Basic SELECT model, the biggest problem is to find the event that happened on the top of the socket (the essence of socket is the file handle, so the quantity is huge)

Sound trigger:

2.4 Real-time signal model recommended by kernel

2.6 EPOLL model recommended by kernel

FreeBSD

Basic SELECT model

Kqueue model triggered by the edge

Performance assessment:

Basic tests show that at the same time, the number of concurrent connections, the delay and throughput of each connection, the Linux 2.6 kernel is a winner, its performance significantly exceeds 2.4 kernels and freebsd. All types of Unix systems are far from behind. Under the comparison of various IO models, the EPOLL of the Linux2.6 kernel is also a winner, and the IO completion port is still the last one. Obviously, the requirements for ease and graphic performance make Windows not suitable as a server-side. operating system.

Model of application system:

Basic Web Server:

1 Provision of static pages:

Memory image file

Direct file sent, reduce the data from the core to the application layer and then copy to the core overhead

There is a corresponding system call in Windows and Linux environments.

The core server, complete the basic HTTP service directly at the core:

Khttpd

2 Provide of dynamic content:

Basic hard-coding methods provide dynamic pages that use simple applications closely related scripting languages,

Using universal scripting languages:

High performance Lua

High performance but too large Java

Other scripting languages ​​PHP, ASP, etc.

3 database system

Are you accessing the database server through the network?

Oracle, Sybase, SQL Server, and other database servers

Open source database servers, etc. Open Source database, Mysql, MSQL, Postgres

local:

Berkely DB

If complex transaction processing and recovery are not required, you can use simple and high performance, basic B * Tree storage mechanisms.

4 J2EE and .NET framework, the benefits and cost of complexity.

Other application servers:

database application

online game

Streaming media play, RTP and other non-wide-known agreements

Next generation application? P2P and BT

New ideas, the benefits, of course, will bring new questions:

It may affect the entire Internet bandwidth and flow

Possible legal issues

Here's the application system, good design is also very important:

Real high performance programming

More small, more fast

More Simple, More Fast

Smaller code faster

Simple simple code faster

Modern computer system, speed often depends on the hit of CPU Cache.

Therefore, smaller, simpler code often achieve better performance.

l Delete redundant code, in contrast, and put it there, even if it is not used, it will affect the performance of the system.

l Do not underestimate or exceed the optimization of the compiler, in addition to the information that the code itself can provide, the compiler never know what you want to do.

l Don't dream reuse, the possibility of using your code in code level is close to 0

L-layer package is the efficiency of killer

l Dynamic runtime analysis, type ... The problem brought is far more than the benefits of commitment.

l Special, dedicated to dedication, limit your code in a very specific scenario, common code often means inefficient, potential misuse and other errors.

l Don't do things outside the expectation, all Bonus is to pay for it!

l Optimize the most common situation, not the worst case.

l Memory allocation and release are very expensive operations (from time, stability is all)

l Don't imagine, use tools to observe your code, vTune or GPROF, etc., only this can find true bottlenecks.

转载请注明原文地址:https://www.9cbs.com/read-22259.html

New Post(0)