You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.7 KiB

  1. <h1>Pinging Reliability Tips</h1>
  2. <p>Sending monitoring signals over public internet is inherently unreliable.
  3. HTTP requests can sometimes take excessively long or fail completely
  4. for a variety of reasons. Here are some general tips to make your monitoring
  5. code more robust.</p>
  6. <h2>Specify HTTP Request Timeout</h2>
  7. <p>Put a time limit on how long each ping is allowed to take. This is especially
  8. important when sending a "start" signal at the start of a job: you don't want
  9. a stuck ping prevent the actual job from running. Another case is a continuously
  10. running worker process which pings SITE_NAME after each completed item. A stuck
  11. request would block the whole process, so it is important to guard against.</p>
  12. <p>Specifying the timeout depends on the tool you use. curl, for example, has the
  13. <code>--max-time</code> (shorthand: <code>-m</code>) parameter:</p>
  14. <div class="bash highlight"><pre><span></span><code><span class="c1"># Send a HTTP, 10 second timeout:</span>
  15. curl -m <span class="m">10</span> PING_URL
  16. </code></pre></div>
  17. <h2>Use Retries</h2>
  18. <p>To minimize the amount of false alerts you get from SITE_NAME, instruct your HTTP
  19. client to retry failed requests several times.</p>
  20. <p>Specifying the retry policy depends on the tool you use. curl, for example, has the
  21. <code>--retry</code> parameter:</p>
  22. <div class="bash highlight"><pre><span></span><code><span class="c1"># Retry up to 5 times, uses an increasing delay between each retry (1s, 2s, 4s, 8s, ...)</span>
  23. curl --retry <span class="m">5</span> PING_URL
  24. </code></pre></div>
  25. <h2>Handle Exceptions</h2>
  26. <p>Make sure you know how your HTTP client handles failed requests. For example,
  27. if you use a HTTP library which raises exceptions, decide if you want to
  28. catch the exceptions, or let them bubble up.</p>