Netcore High Performance Web server Kestrel analysis

Source: Internet
Author: User

Kestrel is one of the Web servers in Aspnetcore, with its own cross-platform, lightweight, high-performance features

In the Ryzen 1600 12-core CPU test environment, the number of instantaneous processing requests per second can reach more than 2w5, comparable to Netty, equivalent to the same environment IIS ASP. NET processing power of about 3 times times

To understand why Kestrel is so strong, I downloaded the source code from GitHub for analysis, with the address:

Https://github.com/aspnet/KestrelHttpServer

The Kestrel Port listener parameter uses the EndPoint , which contains the IP and port information that needs to be monitored

For each EndPoint , a itransport instance is used for listening, Itransport is created by the itransportfactory factory

itransportfactory is a single instance, the default is sockettransportfactory , which is set by the Usekestrel startup parameter

There are two kinds of transportfactory implementations of Kestrel

Kestrel.Transport.Libuv

Kestrel.Transport.Sockets

At startup, first obtain the itransportfactory from servicecollection , and then use the factory to create a itransport

Sockettransport Creating an array of schedulers at initialization _schedulers = pipescheduler[]

The array size is ioqueuecount , ioqueuecount is read from the configuration, the default number is the number of CPU threads, and the number of threads is less than 16 is 16

If ioqueuecount is specified and the value is 0, an exception is thrown

In Sockettransport , the scheduler uses the ioqueue implementation, which is implemented by ThreadPool.QueueUserWorkItem Add a work task to a work queue in a thread pool

After the Sockettransport is started, a looping task is run, each loop loops through all the schedulers, obtains the request information through the Awit Acceptasync , and then hands over the connection to the scheduler

For the Socket Data Processing section, asynchronous Socket,scoket implementations of different platforms are not the same

Under Windows, Scoket is a simple package for Windows Socket2, and Windows Socket2 is a set of blocking/nonblocking Win32API

For Linux implementation, I am still in the study, the understanding of it is not deep enough

In general, the number of schedulers does not have a significant impact on the processing power of kestrel, and the processing of the request is done by adding a work task to the thread pool, which is determined by the number of threads in the kestrel.

In general, Kestrel is a simple encapsulation of asynchronous sockets, and using the thread pool, memory pool, implements the actor model, all requests are non-blocking processing, so the processing ability to improve a lot

Of course, Aspnetcore Middleware pipeline mode is also one of the reasons for its good performance

Netcore High Performance Web server Kestrel analysis

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.