abp icon indicating copy to clipboard operation
abp copied to clipboard

Bundling & Minification - MVC - possible issues in clustered environment (k8s)

Open leonkosak opened this issue 2 years ago • 5 comments

Bundling & Minification Functionality for MVC https://docs.abp.io/en/abp/latest/UI/AspNetCore/Bundling-Minification

image

We have multi-instance k8s environment and outside ping service which pings API every 5 minutes.

Strangely, it takes time that application loads in web browser. This issue is not always present, but still often. We currently have only one instance, but this issue still exists.

What could possibly go wrong here that bundling is taking so much time and that is not retrieved from cache?

Thank you.

leonkosak avatar Sep 23 '22 11:09 leonkosak

The way that bundling & minification works in abp (bundling, minification and version is generated on the first request) is not good solution for clustered (multi-instance) environments, because each instance generates it's own version of tha same files (css, js). Even if web browser (some client) has the latest versions of js in css, it will re-download because it is redirected to different instance. The only solution which I see is good is compile-time bundling, minification and version generation. Bundling and minification also cause that first request is more demanding (resource-wise) and this is also not ideal solution.

@hikalkan, @maliming what do you think?

leonkosak avatar Sep 25 '22 15:09 leonkosak

We removed bundles and referenced minified library files directly and described issue disappeared. @maliming, is somehow possible that bundles (with minification) are created during compilation?

leonkosak avatar Sep 28 '22 14:09 leonkosak

@maliming did you find any particular reasons?

leonkosak avatar Oct 12 '22 04:10 leonkosak

hi

I will check this later. : )

maliming avatar Oct 12 '22 05:10 maliming

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 16 '22 03:12 stale[bot]

@maliming, any updates on this why (apparently) bundling and minification is done during runtime and not compile time?

leonkosak avatar Oct 09 '23 06:10 leonkosak

hi

I will confirm this. Thanks.

maliming avatar Oct 09 '23 12:10 maliming

The problem is that if files are cached on CDN, then loading is fast, otherwise many times not. I cannot explain this weird behavior.

leonkosak avatar Oct 09 '23 17:10 leonkosak

I think this is a more serious problem as each web server ends up generating its own unique set of URL's for the bundle. Of course being able to offload bundles onto CDN's would be a big improvement but perhaps the signatures of the bundles could use some kind of build date/time to help maintain consistency across web farm deployments?

jasenf avatar Oct 16 '23 18:10 jasenf

Yes @jasenf, this is probably the root issue of bundling (and minification) in abp.

leonkosak avatar Oct 16 '23 19:10 leonkosak

No need to hurry @maliming, because this issue is not critical (and can be avoided when not using bundling functionality). It's really an issue in multi-instance environment (and never in single-instance as far as I tested).

leonkosak avatar Oct 17 '23 10:10 leonkosak

Turning off bundling in a product environment isn't really an option.

If we need a multi-instance environment, by definition we are getting a ton of traffic. Turning off bundling under that scenario would be significantly detrimental. It would literally be better to keep bundling on and just send and cache different bundles from each server. Not optimal.

If we could turn of Abp bundling and use native bundling that would go a long way, as ASP.NET bundling has support for CDN URL's as well. The problem on that front are the dynamically generated abp files can't be included in those..... or can they?

We are in the process of building what we hope to be a very large and public SaaS/website so I'm paying extra attention to this issue at the moment, sorry to bother ;-)

jasenf avatar Oct 17 '23 11:10 jasenf

hi @leonkosak

What could possibly go wrong here that bundling is taking so much time and that is not retrieved from cache?

Can you check redis? Is there maybe a network delay?

Please set the log level to Debug and check the logs.

        Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Debug()
            .Enrich.FromLogContext()
            .WriteTo.Async(c => c.File("Logs/logs.txt"))
            .WriteTo.Async(c => c.Console())
            .CreateLogger();

is somehow possible that bundles (with minification) are created during compilation?

The bundle supports change at runtime, so it can't be generated during compilation.

maliming avatar Oct 18 '23 06:10 maliming

Redis works fine in it is running inside the same containerized environment. When we remove scripts from bundles, everything is fast (and we have tiered MVC architecture which requires Redis for caching permissions,...).

The bundle supports change at runtime, so it can't be generated during compilation. Is it possible to add an additional parameter in Script/StyleBundle method in middleware that tells if a bundle can be generated in compile time?

leonkosak avatar Oct 18 '23 07:10 leonkosak

hi

Please set the log level to Debug and check the logs to see what operations have problems.

Is it possible to add an additional parameter in Script/StyleBundle method in middleware that tells if a bundle can be generated in compile time?

It's currently impossible.

maliming avatar Oct 18 '23 07:10 maliming