This article is a mirror article of machine translation, please click here to jump to the original article.

View: 4002|Reply: 2

[Source] ASP.NET Core (24) is based on Refit, MemoryPack high-performance communication

[Copy link]
Posted on 2023-9-30 22:10:36 | | | |
Requirements: Based on the microservice architecture used by ASP.NET Core, some services are infrastructure (basic services) that need to communicate frequently with a certain service, and high performance and low latency are particularly important.

Using the MemoryPack protocol to serialize data has two advantages over using JSON: fast serialization and small transfer of content, which improves performance.

Review:

MessagePack and protobuf-net performance benchmarks
https://www.itsvse.com/thread-10655-1-1.html

.net/c# Xml, Json, Hessian, Protocol Buffers serialization comparison
https://www.itsvse.com/thread-4675-1-1.html

The interface was called 200,000 times using MemoryPack and JSON, and the results were as follows:



MemoryPack takes 29,895 milliseconds
JSON takes 34,283 milliseconds

Since I amLocal test, the gap is not very noticeableWhen cross-host calls, fields increase, and data volume increases, I believe the gap will be more obvious.

ASP.NET Core configuration supports the MemoryPack protocol

Since the object is serialized using the MemoryPack protocol and then sent over the HTTP protocol, ASP.NET Core needs to support the MemoryPack protocol, and a new MemoryPackInputFormatter class is created, the code is as follows:

Then MvcOptions adds support for the MemoryPack protocol, with the following code:

Define a transport object with the following UserProfile code:


The controller method adds an interface with the following code:

The console uses Refit to send HTTP requests

A console application uses MemoryPack to serialize objects and send HTTP requests to interfaces, with the following code:

The test is as follows:



When using MemoryPackSerializer to serialize an object, the following code will give an error:


System.Object is not registered in this provider

It should be a MemoryPack bug, modified as follows:

(End)





Previous:Windows 11 File Explorer stuttering, stuck solution
Next:.NET/C# new feature record type
 Landlord| Posted on 2023-10-1 08:06:35 |
System.Object is not registered in this provider

This issue is an issue with Refit, as follows:




 Landlord| Posted on 2024-12-31 21:47:28 |
Download the file with Refit to get a response flow (Note:The entire downloaded file stream is not loaded into memory



Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com