Blazor Server Usage Scenarios and Performance in .NET Core 3.0

Since the release of Blazor Server with .NET Core 3.0 last month, many people have shared with us their enthusiasm for the possibility of creating a web-based client interface using only with .NET and C #. At the same time, we also heard many questions about what Blazor Server is, how it is associated with Blazor WebAssembly, and for what scenarios Blazor Server is best suited. Should I choose Blazor Server for my client-side web interface or wait for Blazor WebAssembly? This post is intended to answer these questions and give an idea of ​​how Blazor Server works on a scale, and how we see the development of Blazor in the future.







What is Blazor Server?



Blazor Server applications host Blazor components on the server and handle user interface interactions through the SignalR connection in real time. When a user interacts with the application, user interface events are sent to the server through a connection that is processed by the various components that make up the application. When a component processes a user interface event, it is displayed based on its updated state. Blazor compares recently rendered output to previously rendered, sends the changes back to the browser and applies them to the DOM.







Because Blazor Server applications run in .NET Core on a server, they take full advantage of running .NET Core, including excellent runtime performance and the use of advanced tools. Blazor Server applications can use the entire ecosystem of .NET Standard libraries without any browser restrictions.



When should you use Blazor Server?



Blazor Server allows you to add a rich interactive interface to .NET applications without the need for JavaScript. If you want a one-page application interactivity in a .NET application, then Blazor Server is a great solution.



Blazor Server can be used to write completely new applications or to complement existing MVC and Razor Pages applications. There is no need to rewrite existing application logic. Blazor is designed to work with MVC and Razor Pages, not replace them. You can continue to use MVC and Razor Pages for server rendering needs, while Blazor is used for client-side user interface interaction.



Blazor Server is best suited for scenarios in which you have a reliable, low latency network connection, which is usually achieved when the client and server are geographically located on the same continent. Applications that require instant updates with very high fidelity with every tiny click of the mouse, such as real-time games or drawing applications, are not suitable for Blazor Server. Because Blazor Server applications require an active network connection, stand-alone scripts are not supported.



Blazor Server is also useful when you want to transfer work from a client to a server. Blazor Server applications require only a small download to establish a connection to the server and to handle user interface interactions. All the hard work of running the application logic and visualizing the user interface is done on the server. This means that Blazor Server applications load quickly, even as application functionality grows. Because the client side of the Blazor Server application is very lightweight, it is a great solution for applications that should run on low-power devices.



Using Blazor Server to scale



Blazor Server can scale from small internal business applications to large Internet applications. While .NET Core 3.0 was still in preview, we tested Blazor Server to understand how scaling works. We placed the Blazor Server application under the load of active clients and monitored the delay in user interaction. In our tests, one instance of Standard_D1_v2 in Azure (1 vCPU, 3.5 GB of memory) could handle more than 5000 concurrent users without reducing the delay.



The Standard_D3_V2 instance (4 vCPUs, 14 GB of memory) handled more than 20,000 concurrently running clients. The main bottleneck for further processing of the load was the available memory. Do you achieve this scale in your own application? This will depend largely on how much additional memory your application requires per user. But for most applications, we find this level of scaling quite reasonable. We also plan to publish additional updates to improve the scalability of Blazor Server in the coming weeks. So stay tuned!



What is Blazor WebAssembly?



Blazor is a user interface framework that can work in different environments. When you create user interface components using Blazor, you get the flexibility to choose how and where they will be placed and launched. In addition to running user interface components on a server with Blazor Server, you can run the same components on a client using Blazor WebAssembly. This flexibility means that you can adapt to the needs of your users and avoid the risk of being tied to a specific application hosting model.



Blazor WebAssembly applications host components in a browser using the .NET runtime based on WebAssembly. Components handle user interface events and execute rendering logic directly in the browser. Blazor WebAssembly applications use only open web standards to run .NET client code without the need for any browser plug-ins or code porting. As with Blazor Server applications, the Blazor platform processes the compared output with what was previously displayed and updates the DOM accordingly, but in Blazor WebAssembly, user interface rendering is handled on the client side.







When do I need to use Blazor WebAssembly?



Blazor WebAssembly is still in preview and not yet ready for use. If you are looking for a ready-to-use solution, we recommend Blazor Server.



Following the release of Blazor WebAssembly (May 2020), it will allow Razor components and .NET code to run in a browser on a user's device. Blazor WebAssembly applications help transfer work from the server to the client. The Blazor WebAssembly application can use the computing resources, memory and storage resources of the client device, as well as other resources available through the standard browser APIs.



Blazor WebAssembly applications do not require .NET on the server and can be used to create static sites. The Blazor WebAssembly application is simply a collection of static files that can be hosted using any static hosting service, such as GitHub pages or Azure website static hosting. In combination with the service worker, Blazor WebAssembly can work completely offline.



In conjunction with .NET on the Blazor server, WebAssembly provides complete web stack development. You can share code, use the .NET ecosystem, and reuse your existing .NET skills and infrastructure.



Including the .NET runtime in your web application increases the size of the application, which affects the load time. Although there are various methods to mitigate this problem (pre-rendering on the server, HTTP caching, IL connection, etc.), Blazor WebAssembly may not be the best choice for applications that are very sensitive to load size and time. downloads.



Blazor WebAssembly applications also require a browser that supports WebAssembly. WebAssembly is supported by all modern browsers, including mobile and desktop browsers. However, if you require support for older browsers without WebAssembly support, then Blazor WebAssembly is not for you.



Blazor WebAssembly is optimized for user interface rendering scenarios, but is currently not suitable for performing heavy processor loads. Today, Blazor WebAssembly applications use the .NET IL interpreter to execute .NET code that does not have the same performance as the native .NET runtime with JIT compilation. We are working to better deal with this scenario in the future by adding support for compiling your .NET code directly into WebAssembly instead of using an interpreter.



You can change your mind later



Regardless of whether you choose Blazor Server or Blazor WebAssembly, you can always change your mind later. All Blazor applications use a common component model, Razor components. The same components can be hosted in the Blazor Server application or the Blazor WebAssembly application. So, if you start with one Blazor hosting model, and then decide that you want to switch to another, it is very simple.



What's next with Blazor?



With the release of Blazor WebAssembly, we plan to expand Blazor to support not only web applications, but also Progressive Web Apps (PWA), hybrid applications, and even fully native applications.





These three new products are currently experimental. We expect an official announcement of support for Blazor PWA and Blazor Hybrid applications using Electron during the .NET 5 period (November 2020). There is no roadmap to support Blazor Native yet, but this is an area we are actively exploring.



Total



With .NET Core 3.0, you can create a rich, interactive client-side user interface today with Blazor Server. Blazor Server is a great way to add client-side functionality to existing and new web applications using your existing .NET skills and resources. Blazor Server is designed to meet all the needs of your web application. Blazor WebAssembly is still in preview, but is expected to be released in May next year. In the future, we look forward to continued development of Blazor to support PWA, hybrid applications, and native applications. Now we hope you try Blazor Server by installing .NET Core 3.0 !



All Articles