I have an Angular application based on an nginx image started as Docker container on an Ubuntu 22.04 server.
If the login screen of this application is loaded in Chrome, the performance sometimes is very bad. It takes up to 5 minutes to load the login page. DevTools - Network shows pending status for javascript, css and svg files. During loading of login page, the application doesn’t send any requests to the backend and therefore nothing is accessed from the database.
The weird thing is: about half of the time first time loading is fast (1-3 seconds) and half of the time it takes a few minutes.
This is my scenario. Everything is running as a Docker container:
Angular frontend application (based on nginx image)
Laravel backend application with nginx and application container
The performance issue doesn’t only occur in Chrome, but also in Microsoft Edge. Running the Angular application without Docker, there is no performance issue.
Hard to say without more information, but maybe this will help (warning: only for development, not for production / CORS misconfigurations can have a significant impact on the security of web applications)
If you use docker compose with bind mounts this might be a better alternative:
4 steps to improve Laravel + Docker performance issues:
Checking for DNS issues: I tried it, but nothing changed
Installing PHP Opcache: was already installed in our PHP backend. But the problem is not on backend side, but loading of javascript, css or svg files on frontend side before any request is sent to the backend.
Configuring Nginx to handle OPTIONS requests: see 2.
Installing docker-sync: every documentation I found about this point, says that it improves performance on Mac and Windows, but not on Ubuntu
Use Compose Watch: the Angular frontend only shares /etc/ssl with SSL certificates as a volume.
After reading it again, I think it’s more likely to be the NGINX web server. If there are only sometimes performance drops and only with static files, then it is more likely that it is due to the NGINX configuration.
You should check your NGINX configuration to see if you can optimize settings such as sendfile_max_chunk or worker_processes.
It is also possible that the problems only exist if there is too much access to your application.
Maybe it will help to improve the performance. The blog post is a little older but most of it should still be valid today (Note on the implementation of HTTP/2 and SPDY in the article - HTTP/3 has been standardized as RFC 9114 in 2022):
Optimizing the caching of static files and activating Gzip compression can also prevent such perfomancy drops (warning: only for production, not for development):
And as a bonus Server-side rendering:
Note: It is also possible that hardware problems on the server explain the bottleneck in accessing static files. For example, a defective hard disk, a processor that is too slow, too little memory or a hard disk that is too slow. Perhaps resources for Docker or the container are also limited too much.
And just another tip:
Try NGINX Unit instead of NGINX.
Unit is a modern and powerful web server and an app runtime environment that is stable even with high data traffic.
I did it for you this time @christinehabel, but the Dockerfile doesn’t seem to be a valid Dockerfile. I guess, you tried to make it a list. Please, next time do what @bluenobly suggested with the shared link