[squid-users] ICAP Persistent Connections vs Retries (with code review)

Juan Ramírez jramirez.uy at gmail.com
Fri May 12 00:49:34 UTC 2017


Hi,

Mi name is Juan, I am a Software Engineer from Uruguay. I think this
message is more suited to the squid-dev mailing list due to the
developer-oriented nature of the message but, given that the development
list is for people who actually contributes code to Squid, I chose to post
here.

I started using Squid a few days ago in order to test its
content-adaptation capabilities. The plan was to test the ICAP
implementation first and then maybe try the eCAP API as well.

In order to test ICAP, I based my code in the open source PYICAP project, I
also ran some tests using the C-ICAP server.

It came to my attention that, even when persistent connections is enabled,
Squid closes the ICAP connection everytime a new request arrives, like this:

1. A new request arrives
2. Squid creates a connection to the ICAP server
3. Content is adapted and returned to the client
4. Squid returns the connection to the connection pool
5. A new requests arrives
6. Squid closes the active connection
7. Squid opens a new connection to the ICAP server

Note: I am using only the RESPMOD method.

This tests was performed using Squid 3.5.x. I downloaded the last available
tarball (squid-4.0.19), and run the same test, which gave the same results.

So I started digging into the source code and found something interesting:

File:
    /src/adaptation/icap/ServiceRep.cc
Function:
    Adaptation::Icap::ServiceRep::getConnection(bool retriableXact, bool
&reused)

Code:
    if (retriableXact)
        connection = theIdleConns->pop();
    else {
        theIdleConns->closeN(1);
    }

The connection is taken from the set of idle connections  ONLY if
retriableXact is set to true.

File:
    /src/adaptation/icap/Xaction.cc
Function:
    Adaptation::Icap::Xaction::openConnection()

Xaction uses the member variable 'isRetriable' as parameter for
ServiceRep::getConnection.

The function Xaction::disableRetries() is called from a lot of places, but
in my test case was called only two times (per request):

   1. In the function Adaptation::Icap::Xaction::noteCommRead, when
Comm::ReadNow returns Comm::OK.

   2. In the function Adaptation::Icap::Xaction::closeConnection,
because reuseConnection is set to true.

I am not sure if Xaction objects are reusable, it seems that they are
because setting isRetriable to false is affecting the way connections are
reused.

Anyway, I think the concept of retriability shuld not be confused with the
concept of reusability, but I haven't gone deep enough in order to ensure
that.

I appreciate your comments on this. Don't hesitate to contact me should any
additional information be needed.


-- 
Juan
:wq
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squid-cache.org/pipermail/squid-users/attachments/20170511/7cfcdb0c/attachment-0001.html>


More information about the squid-users mailing list