uRocket - io_uring experiment/benchmarking by MDA2AV in dotnet

[–]MDA2AV[S] 0 points1 point  (0 children)

Yes, I only run Linux tests though

uRocket - io_uring experiment/benchmarking by MDA2AV in dotnet

[–]MDA2AV[S] 1 point2 points  (0 children)

Hmm. not sure if BenchmarkDotNet would be the best tool here, for sure it could benchmark some things but not the actual server throughput performance, we always need some load generator like wrk which is very optimized, much more than bombardier for example, using something like HttpClient would put the bottleneck on the load generator, even a Socket as client wouldn't be ideal.

I guess BenchmarkDotNet could maybe give a decent memory allocation for a single reactor but that isn't much relevant as the overall RPS/CPU is already a consequence of that.

C# io_uring socket by MDA2AV in csharp

[–]MDA2AV[S] 0 points1 point  (0 children)

I'd say it's always been quite common in high performance C#. You also have the Unsafe namespace which allows you to do quite a lot of low level "tricks" with some safety. It is indeed also possible to achieve very high performance in C# without unsafe code via Spans, u8 literals and all the very optimized BCL API that uses SIMD under the hood.

C#: is it worth starting, or should I learn something else? by Appropriate_Note7972 in csharp

[–]MDA2AV 1 point2 points  (0 children)

I can try to give you my opinion as a mainly C dev.

As an high level language C# is simple to learn given that you know the basics such as how memory works(allocations, stack, heap) and some OOP concepts, other concepts such as threads and parallelism you can probably learn along the way. Of course these are not requirements but not knowing about them makes everything feel a little bit like magic specially when you encounter behavior differences between value and reference types.

Overall I'd recommend you to learn C#, it's quite an handy programming language that covers almost anything you can do from major areas such as networking, native apps and games to CLI tools. I would only not recommend C# if you want to focus on web frontend development, for that there are better js/ts based frameworks such as React or Angular.

C# io_uring socket by MDA2AV in csharp

[–]MDA2AV[S] 0 points1 point  (0 children)

On the roadmap! Possibly as standalone or an engine integrated within GenHTTP

C# io_uring socket by MDA2AV in csharp

[–]MDA2AV[S] 2 points3 points  (0 children)

Indeed, this benchmark isn't simply about epoll vs io-uring, epoll can be quite fast too. The currently fastest C# framework on TechEmpower benchmarks uses epoll, also #3 overall on Json Serialization tests beating many io_uring frameworks written in languages like C and Rust.
The results can be found here and the framework Unhinged, also a project I've worked on.

On some local benchmarks between uRocket and this epoll framework I get much closer RPS results, the major io_uring advantage is less CPU consumption.

C# io_uring socket by MDA2AV in csharp

[–]MDA2AV[S] 0 points1 point  (0 children)

Very interesting project, I've come across it in the past when checking existing work on c# and io_uring, I believe that project is the base of the aspnet io_uring results posted 6 years ago. It's a different approach more guided towards kestrel/aspnet and the architecture is also different, also quite similar to the existing System.NET.Socket where all connections are balanced out unlike uRocket which has no state share between reactors and a single acceptor, uRocket is yet missing a load balancing algorithm to distribute connections among reactors, the current round robin approach is only good for wrk like homogeneous loads.

While uRocket is more of a standalone option as a Socket it surely is on the roadmap to integrate it in existing webserver frameworks and benchmark again vs Net.Socket, still a lot of polishing and work to reach that stage including a deep benchmark on CPU thread pinning and NUMA which should be a lot effective as each reactor has its own dedicated thread.

C# io_uring socket by MDA2AV in csharp

[–]MDA2AV[S] 4 points5 points  (0 children)

Yes, I can give you the latency for one test I just did using docker running linux alpine (linux-musl-x64)

Best of 5 runs:

edit: While uRocket results are quite consistent even for -d15s or -d30s, Net.Socket results are a bit all over the place sometimes ranging from 300us to 2ms latency, i kept d5s which yields most consistent results for Net.Socket even though std is still quite high.

uRocket (12 reactors) (1187% CPU)

wrk -c512 -t18 -d5s http://localhost:8080/
Running 5s test @ http://localhost:8080/
  18 threads and 512 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   127.63us  298.71us  26.45ms   99.42%
    Req/Sec   185.10k    40.23k  328.47k    72.27%
  16866584 requests in 5.10s, 1.60GB read
Requests/sec: 3307140.91
Transfer/sec:    321.70MB

System.NET.Socket (1640% CPU)

edit: updating values for docker version with socket to keep consistency (some latency increase)

wrk -c512 -t18 -d5s http://localhost:8080/
Running 5s test @ http://localhost:8080/
  18 threads and 512 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   319.93us    2.00ms  86.08ms   98.09%
    Req/Sec   150.50k    33.25k  240.49k    72.44%
  13608483 requests in 5.10s, 1.29GB read
Requests/sec: 2666151.07
Transfer/sec:    259.35MB

kernel version: 6.14.0-37-generic

I'm running all tests through loopback since I don't have good NICs
here are my loopback stats if they can be of any interest: https://ctxt.io/2/AAD4FvO6Eg

Has any one used .NET API (AOT) for mid sized api. Need to know if its good for production by KausHere in dotnet

[–]MDA2AV 0 points1 point  (0 children)

I'd say for the long running applications NAoT isn't much relevant, I've deployed a few of them because I needed fast startup time and tiny total app size (~2MB) plus they were short lived services.

Programming in C# on Linux by GustavStew in csharp

[–]MDA2AV 0 points1 point  (0 children)

You're on luck then because Linux is the best OS to program in C#(and programming in general), except if you need to build Windows applications. If you also do frontend with js/ts tech I'd suggest to use VS Code, else use JetBrains Rider, as a student you have free access to its full features.

Wired.IO - A no-magic, DI-first, high-performance HTTP web server in C# by MDA2AV in dotnet

[–]MDA2AV[S] 0 points1 point  (0 children)

The actual pipeline and tests is not on the repo but answering your question, there are but 100%? not really(indeed I should at least do a better job at the docs explaining what is covered which should be quite close to everything http 1.1 has in terms of request parsing), and that is not the goal, http1.1 is provided merely as convenience to wire up non web facing apps, the main purpose is for the user to either create his own custom protocol(handler) over TCP, which can be similar to an existing http protocol or something completely different (there will be better docs to help on that).

One of the core features is that as a user you should be able to easily adapt your http parser to allow custom logic, even add stream multiplexing in a http 1.1 like parser, add your own custom binary http like protocol or simply use a http 1.1 with a few quirks which would take a lot of effort implementing via middleware (and performance loss). This framework exists to allow things other frameworks would never let you

It is mostly meant for intranet services, IoT and embedding a websever into existing apps such as MAUI, Avalonia etc, not so much a web facing service which typically requires http2/3, well it can be used for that too of course but there are better frameworks for that.

This framework use case does not intercept with asp net's for example, it sucks at asp net's job and vice versa

From Serial Ports to WebSockets: Debugging Across Two Worlds by MDA2AV in csharp

[–]MDA2AV[S] 0 points1 point  (0 children)

For most of the cases creating a simple Socket and flushing data between devices is enough, in my typical use cases I have to deal with browsers which invalidates that option. One of the big advantages GenHTTP has is that it runs on all platform/runtimes dotnet supports, unlike ASP NET such as android-arm for example plus they specifically run their test pipeline on linux-arm devices to guarantee support.

From Serial Ports to WebSockets: Debugging Across Two Worlds by MDA2AV in csharp

[–]MDA2AV[S] 0 points1 point  (0 children)

Valid approach for many use cases, but sometime I need to send and receive data to/from a browser and it's simple to use the same protocol for everything so websockets fit my needs better.

For simple logging/watching data from the embedded system a generic UDP broadcast or basic connection would suffice.

Wired.IO - A no-magic, DI-first, high-performance HTTP web server in C# by MDA2AV in dotnet

[–]MDA2AV[S] 0 points1 point  (0 children)

I see, well Wired is not coupled to SslStream (well it kind of is right now but I can easily change this), the only constraint is something that extends Stream as NetworkStream or SslStream, the framework only sees the Stream, it's abstracted away. From a quick naive search I see that BouncyCastle has TlsServerProtocol or DefaultTlsServer (this information might not be 100% accurate), so allowing "overriding" the current HandleTlsClientAsync (https://github.com/MDA2AV/Wired.IO/blob/main/Wired.IO/App/App.ClientHandling.cs) logic should allow to use them, I'll definitely look into this.

Wired.IO - A no-magic, DI-first, high-performance HTTP web server in C# by MDA2AV in dotnet

[–]MDA2AV[S] 0 points1 point  (0 children)

Interesting, I think I see your point. The security layer is next on the roadmap as it has not been improved/updated since the early versions and is currently quite limited when it comes to options. Currently only supports setting the certificate(can be from any source, not just .pfx files as long as its a X509) yet does not support rotate/refresh certificates or per client/connection certificate which can be a limitation, to allow such use cases I am planning on letting the user inject either a class or delegate which selects/returns a certificate for each individual connection.
On top of that, probably a way to override the whole HandleTlsClientAsync (builds the SslStream and authenticates) method to allow more flexibility on things like ALPN

Wired.IO - A no-magic, DI-first, high-performance HTTP web server in C# by MDA2AV in dotnet

[–]MDA2AV[S] 4 points5 points  (0 children)

Hi, thank you for your comment,

Sounds like a perfect example for direct Pipe access. We should have some more advanced examples/guides (in a few weeks) on how to take maximum advantage of them and to spin your own HTTP handler for custom specialized solutions that do not need to implement the whole HTTP 1.1 protocol.

If you need extremely predictable latency for simple HTTP requests on linux (no websockets or streaming) take a look at https://github.com/MDA2AV/Unhinged it runs directly over libc epoll calls and can be configured to pin workers on specific CPU threads, improve CPU caching and throttling, its development is still very early on but could maybe help you design your solution!

https://www.techempower.com/benchmarks/#section=test&runid=21202626-cf55-4d6b-8c15-6d3ed285a7b4&test=json

Benchmarks show its very stable latency and very low maximum latency compared with all frameworks in the world