admin管理员组

文章数量:1290226

We are facing an issue where the first API call in our React Native app takes 45-60 seconds due to a slow SSL handshake. After the initial request, subsequent API calls work fine.

Our setup is as follows:

  • Backend: Tomcat (Serving APIs)
  • Reverse Proxy: Nginx (Handles SSL termination)
  • Mobile App: React Native (Using Redux Toolkit Query for API calls)
  • SSL Certificate: Let's Encrypt (Installed on Nginx)

Issue:

Whenever a user opens the app for the first time, the initial API request triggers an SSL handshake delay of 45-60 seconds. This happens only on the first request, and subsequent requests are fast.

What We Have Tried:

  • Enabled SSL Session Resumption in Nginx (ssl_session_cache)

    ssl_session_cache shared:SSL:50m;
    ssl_session_timeout 4h;
    ssl_session_tickets on;
    keepalive_timeout 75s;
    keepalive_requests 100;
    

    Result: No major improvement.

  • Preloaded API Calls in React Native (useEffect)

    useEffect(() => {
      triggerGetData();  // Preload API call to warm up SSL connection
    }, []);
    

    Result: Helped slightly, but still slow for first-time users.

  • Enabled HTTP/2 in Nginx

    listen 443 ssl http2;
    

    Result: No noticeable improvement.

  • Checked SSL Handshake Timing Using OpenSSL

    openssl s_client -connect yourdomain:443 -showcerts -time
    

    Result: Handshake took ~15 sec on first request but was fast on retries.`

本文标签: