ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.32k stars 1.63k forks source link

Slow response on .Net 6 and IIS 10 #1657

Closed vladkhnu closed 1 year ago

vladkhnu commented 1 year ago

I'm having issues when trying to use Ocelot with .Net version 6 deployed on IIS 10.

Previously I used .Net 3.1 with Ocelot 16 and everything were fine, pages opened with expected delay, but after upgrading to .Net 6 usage of every version of Ocelot (16, 17, 18) resulted in extremely big delay: image

Issue is happens periodically, after couple of requests to different endpoints behind Ocelot and persist only in chromium-based browsers (Chrome and Edge) and everything is fine in Firefox.

Ocelot itself does not log any errros and seems works fine but after a number of quick requests issue appears again and again. IIS is configured according to Microsoft suggestions and best practices, like I have App Pool in AlwaysRunning Start mode, preload of site is enabled, etc.

raman-m commented 1 year ago

@vladkhnu Hi Vladyslav! Thanks for so big interest in Ocelot gateway!

First, The periodical appearance of the bug with no logs on Ocelot's side mean that this is not an issue of Ocelot.

Second, You said you use different browsers and behavior is different using those browsers. Pay attention that browsers have different default settings, default environments for building real protocol HTTP-based request. Moreover browsers have different tracers and network tools to catch requests/responses. That's why you can see strange behavior in different browsers. I recommend you to switch your work to canonical API tracking tools like Postman.

Third, Hosting Ocelot in IIS environment is bad idea. Ocelot is not tested well for IIS scenarios. Because it is legacy architectural and hosting approach to deploy gateways at IIS machine. You should know that IIS model is hard, complex and full of useless extra middleware modules of IIS pipeline for hosting full sized ASP.NET web apps with rich frontends like ASP.NET Razor and ASP.NET MVC. So, IIS is optimized for classic ASP.NET web apps. So, you need to stop using IIS deployments, even for localhost scenarios, because it is not necessary.

Fifth, Start using self-hosted Kestrel and Docker image deployments for your API gateway solution. Ocelot is optimized for lightweight API apps deployments in Kestrel web server.

Sixth, Sometimes, and it is best practice for microservices, the client should send pre-flight aka OPTIONS request to wake up a service including gateway service. This is cloud-based problem of readiness and health of a service. Pre-flight request makes a service ready to process real requests (API warm up problem). So, ensure you've sent OPTIONS request before real communication to a service.

Finally, Could you upgrade/prepare new .NET 7 solution referencing Ocelot 19.0.2 package (.NET 7, latest release) please? Use all my recommendations and let us know a new feedback please!

Good luck in your endeavor with Ocelot! 🧒

P.S. Ocelot team considers real exception/error logs of Ocelot app. Next time you need to show real problem in Ocelot app logs.

raman-m commented 1 year ago

Vladyslav,

Could you inform on this issue please? Have you resolved the issue?

Please host gateway app by Kestrel, simple Visual Studio running of web host in console, and let us know the results please! I believe there will be no delays in browsers.

The time is over. The issue cannot be in open state for a months. We need to communicate.

Let's find some workaround within one week please! Your issue will be accepted or declined until June 23.

vladkhnu commented 1 year ago

Sorry for the delay - we found the solution that makes us able to host Gateway on IIS. Before that we tried different combination of .Net and Gateway version with no luck. So the solution was to use Out-of-process hosting model instead of In-process - https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/out-of-process-hosting?view=aspnetcore-6.0

raman-m commented 1 year ago

Aha... You are right. InProcess model is for Kestrel vs Docker, vs Console hosting. OutOfProcess model is for IIS (Express) web server hosting.

Yeah, it was the root cause of the issue! :+1: Glad that your team has found this solution and adapt it to company hosting model.

Thanks for closing the issue!