title: Redmine very slow on first page load after some time of inactivity
body: <p>Every morning, the first person that tries to access Redmine at my work is waiting almost one minute for redmine to load the page. After that, the rest of the team have no problem and almost every page are loading in less than 200ms.</p>
  <p>Here is the log between the last &quot;good&quot; loading and the first &quot;bad&quot; loading of this morning:</p>
  <pre><code>App 103 output: I, [2021-04-16T00:19:24.965247 #103]  INFO -- : Completed 200 OK in 829ms (Views: 553.2ms | ActiveRecord: 1.8ms)
  App 103 output: I, [2021-04-16T03:09:12.511395 #103]  INFO -- : Started GET &quot;/login?back_url=https%3A%2F%2Fmyapp.com%2F&quot; for WWW.XXX.YYY.ZZZ at 2021-04-16 03:09:12 +0000
  App 103 output: I, [2021-04-16T03:09:12.532015 #103]  INFO -- : Processing by AccountController#login as HTML
  App 103 output: I, [2021-04-16T03:09:12.532084 #103]  INFO -- :   Parameters: {&quot;back_url&quot;=&gt;&quot;https://myapp.com/&quot;}
  App 103 output: I, [2021-04-16T03:09:12.694146 #103]  INFO -- : Redirected to https://myapp.com/login?back_url=https%3A%2F%2Fmyapp.com%2Flogin%3Fback_url%3Dhttps%253A%252F%252Fmyapp.com%252F
  App 103 output: I, [2021-04-16T03:09:12.694280 #103]  INFO -- : Filter chain halted as :session_expiration rendered or redirected
  App 103 output: I, [2021-04-16T03:09:12.694473 #103]  INFO -- : Completed 302 Found in 162ms (ActiveRecord: 2.7ms)
  App 103 output: I, [2021-04-16T03:09:13.201746 #103]  INFO -- : Started GET &quot;/login?back_url=https%3A%2F%2Fmyapp.com%2Flogin%3Fback_url%3Dhttps%253A%252F%252Fmyapp.com%252F&quot; for WWW.XXX.YYY.ZZZ at 2021-04-16 03:09:13 +0000
  App 103 output: I, [2021-04-16T03:09:13.205997 #103]  INFO -- : Processing by AccountController#login as HTML
  App 103 output: I, [2021-04-16T03:09:13.206088 #103]  INFO -- :   Parameters: {&quot;back_url&quot;=&gt;&quot;https://myapp.com/login?back_url=https%3A%2F%2Fmyapp.com%2F&quot;}
  App 103 output: I, [2021-04-16T03:09:13.283815 #103]  INFO -- :   Current user: anonymous
  App 103 output: I, [2021-04-16T03:09:13.300562 #103]  INFO -- :   Rendering account/login.html.erb within layouts/base
  App 103 output: I, [2021-04-16T03:09:13.304521 #103]  INFO -- :   Rendered account/login.html.erb within layouts/base (3.8ms)
  App 103 output: I, [2021-04-16T03:09:13.526917 #103]  INFO -- : Completed 200 OK in 321ms (Views: 242.1ms | ActiveRecord: 50.2ms)
  App 103 output: I, [2021-04-16T03:09:15.396901 #103]  INFO -- : Started POST &quot;/login&quot; for WWW.XXX.YYY.ZZZ at 2021-04-16 03:09:15 +0000
  App 103 output: I, [2021-04-16T03:09:15.400666 #103]  INFO -- : Processing by AccountController#login as HTML
  App 103 output: I, [2021-04-16T03:09:15.400741 #103]  INFO -- :   Parameters: {&quot;utf8&quot;=&gt;&quot;✓&quot;, &quot;authenticity_token&quot;=&gt;&quot;*********************************&quot;, &quot;username&quot;=&gt;&quot;myuser&quot;, &quot;password&quot;=&gt;&quot;[FILTERED]&quot;, &quot;login&quot;=&gt;&quot;Connexion&quot;}
  App 103 output: I, [2021-04-16T03:09:15.461825 #103]  INFO -- :   Current user: anonymous
  App 103 output: I, [2021-04-16T03:09:16.117981 #103]  INFO -- : Successful authentication for 'myuser' from WWW.XXX.YYY.ZZZ at 2021-04-16 03:09:16 UTC
  App 103 output: I, [2021-04-16T03:09:16.454431 #103]  INFO -- : Redirected to https://myapp.com/my/page
  App 103 output: I, [2021-04-16T03:09:16.454677 #103]  INFO -- : Completed 302 Found in 1054ms (ActiveRecord: 778.5ms)
  App 103 output: I, [2021-04-16T03:09:16.929227 #103]  INFO -- : Started GET &quot;/my/page&quot; for WWW.XXX.YYY.ZZZ at 2021-04-16 03:09:16 +0000
  App 103 output: I, [2021-04-16T03:09:17.650222 #103]  INFO -- : Processing by MyController#page as HTML
  App 103 output: I, [2021-04-16T03:09:18.625577 #103]  INFO -- :   Current user: myuser (id=208)
  App 103 output: I, [2021-04-16T03:09:18.923542 #103]  INFO -- :   Rendering my/page.html.erb within layouts/base
  App 103 output: I, [2021-04-16T03:09:35.622052 #103]  INFO -- :   Rendered queries/_columns.html.erb (509.9ms)
  App 103 output: I, [2021-04-16T03:09:39.698459 #103]  INFO -- :   Rendered issues/_list.html.erb (3990.1ms)
  App 103 output: I, [2021-04-16T03:09:39.736960 #103]  INFO -- :   Rendered my/blocks/_issues.erb (5549.7ms)
  App 103 output: I, [2021-04-16T03:09:44.899092 #103]  INFO -- :   Rendered queries/_columns.html.erb (1643.8ms)
  App 103 output: I, [2021-04-16T03:09:48.195990 #103]  INFO -- :   Rendered issues/_list.html.erb (3114.5ms)
  App 103 output: I, [2021-04-16T03:09:48.238683 #103]  INFO -- :   Rendered my/blocks/_issues.erb (5564.4ms)
  App 103 output: I, [2021-04-16T03:09:48.271494 #103]  INFO -- :   Rendered my/page.html.erb within layouts/base (29347.8ms)
  App 103 output: I, [2021-04-16T03:10:17.568436 #103]  INFO -- : Completed 200 OK in 59918ms (Views: 57311.4ms | ActiveRecord: 2235.3ms)
  App 103 output: I, [2021-04-16T03:11:32.073474 #103]  INFO -- : Started GET &quot;/projects/myapp-v2?jump=my&quot; for WWW.XXX.YYY.ZZZ at 2021-04-16 03:11:32 +0000
  App 103 output: I, [2021-04-16T03:11:32.075240 #103]  INFO -- : Processing by ProjectsController#show as HTML
  App 103 output: I, [2021-04-16T03:11:32.075285 #103]  INFO -- :   Parameters: {&quot;jump&quot;=&gt;&quot;my&quot;, &quot;id&quot;=&gt;&quot;myapp-v2&quot;}
  App 103 output: I, [2021-04-16T03:11:32.083287 #103]  INFO -- :   Current user: myuser (id=208)
  App 103 output: I, [2021-04-16T03:11:34.636170 #103]  INFO -- :   Rendering projects/show.html.erb within layouts/base
  App 103 output: I, [2021-04-16T03:11:36.682491 #103]  INFO -- :   Rendered projects/_members_box.html.erb (157.3ms)
  App 103 output: I, [2021-04-16T03:11:36.684234 #103]  INFO -- :   Rendered projects/show.html.erb within layouts/base (2048.0ms)
  App 103 output: I, [2021-04-16T03:11:37.452800 #103]  INFO -- : Completed 200 OK in 5377ms (Views: 2762.9ms | ActiveRecord: 620.0ms)
  </code></pre>
  <p>At 2021-04-16T03:10:17.568436 you can see a 200 OK response in <strong>59918ms</strong>.</p>
  <p>I run Remdine docker with a docker-compose file. Redmine is connecting to the host MySQL server and uses the host mail server too (no problem with that).</p>
  <p>Here is the <code>redmine-docker-compose.yml</code> file content:</p>
  <pre><code>version: '3.1'
  services:
    redmine:
      image: redmine:4.2-passenger
      user: &quot;$UID:$GID&quot;
      logging:
        driver: &quot;journald&quot;
        options:
          tag: &quot;redmine-docker&quot;
          mode: &quot;non-blocking&quot;
          max-buffer-size: &quot;4m&quot;
      ports:
        - 8792:3000
      environment:
        REDMINE_DB_MYSQL: 172.17.0.1
        REDMINE_DB_DATABASE: redmine
        REDMINE_DB_PORT: 3306
        REDMINE_DB_USERNAME: redmine
        REDMINE_DB_PASSWORD: ***************
        REDMINE_DB_ENCODING: utf8
        REDMINE_SECRET_KEY_BASE: *************************
      volumes:
      - ./redmine/files:/usr/src/redmine/files
      - ./redmine/themes/PurpleMine2-master:/usr/src/redmine/public/themes/PurpleMine2-master
      - ./redmine/config/configuration.yml:/usr/src/redmine/config/configuration.yml
      - ./redmine/repos:/usr/src/redmine/repos
      - ./redmine/etc/passwd:/etc/passwd:ro
      - ./redmine/usr/src/redmine/Passengerfile.json:/usr/src/redmine/Passengerfile.json
  networks:
    default:
      external:
        name: br-redmine-docker
  </code></pre>
  <p>Here is the <code>configuration.yml</code> content:</p>
  <pre><code>production:
    email_delivery:
      delivery_method: :smtp
      smtp_settings:
        address: 172.17.0.1
        port: 25
        enable_starttls_auto: false
  </code></pre>
  <p>And the <code>Passengerfile.json</code> content:</p>
  <pre><code>{
    &quot;max_pool_size&quot;: 15,
    &quot;pool_idle_time&quot;: 60,
    &quot;min_instances&quot;: 4
  }
  </code></pre>
  <p>Note that I created the Passengerfile.json because of this exact same problem but it did not resolve it at all.</p>
  <p>Here is the content of <code>passwd</code> file (it is just a copy of the file present in the docker image with one more line at the end):</p>
  <pre><code>root:x:0:0:root:/root:/bin/bash
  daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
  bin:x:2:2:bin:/bin:/usr/sbin/nologin
  sys:x:3:3:sys:/dev:/usr/sbin/nologin
  sync:x:4:65534:sync:/bin:/bin/sync
  games:x:5:60:games:/usr/games:/usr/sbin/nologin
  man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
  lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
  mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
  news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
  uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
  proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
  www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
  backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
  list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
  irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
  gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
  nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
  _apt:x:100:65534::/nonexistent:/usr/sbin/nologin
  redmine:x:999:999::/home/redmine:/bin/sh
  hostuser:x:998:996::/home/hostuser:/bin/sh
  </code></pre>
  <p>And I created a <code>.env</code> file with this:</p>
  <pre><code>UID=998
  GID=996
  </code></pre>
  <p><code>hostuser</code> is a user that exists on my host (it's name is <code>redmine</code> on the host but I only needed to assign the right UID and GID in order to keep ownership of the redmine files to this user).</p>
  <p>I also checked the <code>wait_timeout</code>  MySQL variable that closes connections after a period of inactivity but it is on the default value which is 8 hours and my problem appears within approximately 4 hours so it can't be the cause.
  I also wanted to disable <code>tini</code> in case it was that but I can't find any way to do that.
  Any help is appreciated.</p>
  <p>Thank you.</p>