Shiny app - slow loading when acessed first time, then quick

Hi,

I am running a shiny app on a local server: https://www.zmbp-resources.uni-tuebingen.de/timmermans/plant-single-cell-browser-leaf-atlas/

Issue:
I have an issue with the long loading time when the app is accessed from a PC for the first time. It takes about 40s to load it in a browser. Then, when you let the app load completely and when accessed the second time, it shows up immediately. I tested it with Chrome and Firefox on three computers.
I believe that it is because the browser initially caches a lot of data. The app itself does not do any intensive calculations. Though I may be wrong.

My question is:
Is there a way how to reduce the time of initial data caching by, for example, reducing the amount of the data to be locally cached?

Thank you,
Pavel

As a first step I'd start profiling the app to identify the bottleneck. After that you can search for specific fixes.

1 Like

Hi,
I did the profiling. As expected, the longest time takes readRDS (1700 ms). However, this is not this issue. The app runs fairly quickly and smoothly when run locally on PC. The issue with the slow loading happens only when the app running on the server is accessed for the first time from a PC as I described above.

I can reproduce this waiting time only with a fresh chrome session. Edge and Firfox is working fine. Looking into Chrome's dev tools (performance tab) declared most of the waiting time as idle.

The client is just waiting:

Accordingly you'll need to check the server side, which we can't do without code / server access.

The only difference (I can spot) between the slow and the fast chrome session is, that the slow session complains about a missing favicon.ico:

GET https://www.zmbp-resources.uni-tuebingen.de/favicon.ico 404 (Not Found)

This is no longer the case in the fast sessions - see your browsers console. Maybe this GET times out the first time the page is accessed.

This article provides a possible explanation:

What happens in these cases is that upon a file not being found, the website serves an HTML page announcing that the file was not found. In these cases, the html is heavy with inline CSS, JavaScript, etc.

When images, scripts or other files fail to load, a simple HTTP 404 response should be served, and the large 404 html page should only be delivered when a webpage does not load properly. To serve a huge 404 page (or to just load the root page of your site) wastes data and server processing.

1 Like

Hi,
based on your advice, I checked the performance. Then I realized, that the Shiny server automatically turns off the app when not used for 1 minute (default settings). Then, when accessed next time, a new R session is initialized which in this case means loading quite big .RDS files. The result is a long waiting time for the server response. So my initial guess that there is some connection with the data caching was wrong.

I solved the issue by turning the idle timeout off as described here or here.

Thank you for your help.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.