How is failure score calculated in squid?

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 6
  • squid

Issue

  • How is failure score calculated in squid?

Resolution

  • The following code calculates failure score
    183 /*
    184  * This function is designed to serve a fairly specific purpose.
    185  * Occasionally our vBNS-connected caches can talk to each other, but not
    186  * the rest of the world.  Here we try to detect frequent failures which
    187  * make the cache unusable (e.g. DNS lookup and connect() failures).  If
    188  * the failure:success ratio goes above 1.0 then we go into "hit only"
    189  * mode where we only return UDP_HIT or UDP_MISS_NOFETCH.  Neighbors
    190  * will only fetch HITs from us if they are using the ICP protocol.  We
    191  * stay in this mode for 5 minutes.
    192  *
    193  * Duane W., Sept 16, 1996
    194  */
    195 
:
    198 static void
    199 checkFailureRatio(err_type etype, hier_code hcode)
    200 {
    201     static double magic_factor = 100.0;
    202     double n_good;
    203     double n_bad;
    204 
    205     if (hcode == HIER_NONE)
    206         return;
    207 
    208     n_good = magic_factor / (1.0 + request_failure_ratio);
    209 
    210     n_bad = magic_factor - n_good;
    211 
    212     switch (etype) {
    213 
    214     case ERR_DNS_FAIL:
    215 
    216     case ERR_CONNECT_FAIL:
    217     case ERR_SECURE_CONNECT_FAIL:
    218 
    219     case ERR_READ_ERROR:
    220         n_bad++;
    221         break;
    222 
    223     default:
    224         n_good++;
    225     }
    226 
    227     request_failure_ratio = n_bad / n_good;
    228 
    229     if (hit_only_mode_until > squid_curtime)
    230         return;
    231 
    232     if (request_failure_ratio < 1.0)
    233         return;
    234 
    235     debugs(33, 0, "Failure Ratio at "<< std::setw(4)<<
    236            std::setprecision(3) << request_failure_ratio);
    237 
    238     debugs(33, 0, "Going into hit-only-mode for " <<
    239            FAILURE_MODE_TIME / 60 << " minutes...");
    240 
    241     hit_only_mode_until = squid_curtime + FAILURE_MODE_TIME;
    242 
    243     request_failure_ratio = 0.8;        /* reset to something less than 1.0 */
    244 }
    246 ClientHttpRequest::~ClientHttpRequest()
    247 {
    248     debugs(33, 3, "httpRequestFree: " << uri);
    249     PROF_start(httpRequestFree);
    250 
    251     // Even though freeResources() below may destroy the request,
    252     // we no longer set request->body_pipe to NULL here
    253     // because we did not initiate that pipe (ConnStateData did)
    254 
    255     /* the ICP check here was erroneous
    256      * - StoreEntry::releaseRequest was always called if entry was valid
    257      */
    258     assert(logType < LOG_TYPE_MAX);
    259 
    260     logRequest();
    261 
    262     loggingEntry(NULL);
    263 
    264     if (request)
    265         checkFailureRatio(request->errType, al.hier.code);
    266 
    267     freeResources();
    268 
    269 #if USE_ADAPTATION
    270     announceInitiatorAbort(virginHeadSource);
    271 
    272     if (adaptedBodySource != NULL)
    273         stopConsumingFrom(adaptedBodySource);
    274 #endif
    275 
    276     if (calloutContext)
    277         delete calloutContext;
    278 
    279     if (conn_)
    280         cbdataReferenceDone(conn_);
    281 
    282     /* moving to the next connection is handled by the context free */
    283     dlinkDelete(&active, &ClientActiveRequests);
    284 
    285     PROF_stop(httpRequestFree);
    286 }

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.