• Ruslan Drozhdzh's avatar
    plugin/forward: erase expired connections by timer (#1782) · 833e3dda
    Ruslan Drozhdzh authored
    * plugin/forward: erase expired connection by timer
    
     - in previous implementation, the expired connections resided in
       cache until new request to the same upstream/protocol came. In
       case if the upstream was unhealthy new request may come long time
       later or may not come at all. All this time expired connections
       held system resources (file descriptors, ephemeral ports). In my
       fix the expired connections and related resources are released
       by timer
     - decreased the complexity of taking connection from cache. The list
       of connections is treated as stack (LIFO queue), i.e. the connection
       is taken from the end of queue (the most fresh connection) and
       returned to the end (as it was implemented before). The remarkable
       thing is that all connections in the stack appear to be ordered by
       'used' field
     - the cleanup() method finds the first good (not expired) connection
       in stack with binary search, since all connections are ordered by
       'used' field
    
    * fix race conditions
    
    * minor enhancement
    
    * add comments
    833e3dda
persistent.go 4.62 KB