Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 42845DB30 for ; Mon, 22 Oct 2012 21:22:21 +0000 (UTC) Received: (qmail 2938 invoked by uid 500); 22 Oct 2012 21:22:20 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 2882 invoked by uid 500); 22 Oct 2012 21:22:20 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 2800 invoked by uid 99); 22 Oct 2012 21:22:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Oct 2012 21:22:20 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jmarantz@google.com designates 209.85.217.173 as permitted sender) Received: from [209.85.217.173] (HELO mail-lb0-f173.google.com) (209.85.217.173) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Oct 2012 21:22:13 +0000 Received: by mail-lb0-f173.google.com with SMTP id gj3so2723536lbb.18 for ; Mon, 22 Oct 2012 14:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:x-system-of-record; bh=RhvG+EviAeorG6E8VWD3DOTWGJx0nEHA4nRkelVhWd4=; b=k1sjSaoc/izAdOpjZxbTE5LxkFP1rDEglIRCV8YhVm/HJlx35ifCOMKHfmZH1oeIpj +dRau3Ovb6uxOnqdzpDpP94dU3Me1TDcgTYxA6BMulrUcgA1d3G8IBYhKzJ5qUBRlOBC TQNDgZBbhBuNUrMcikznM4aUF/qJ3AaEhiljggmlbNNTjI+s+aZrVC15cOTe5AQKMTKU nc6ZDrlEEm52wJB2gySeTuWw7out80r0wZ/A5tk5iJTkziSduYnRLlCmIH7w/8i3I4oG KD117nf2AEffPLtS3WUjAipeKErpUYgi5vs1dnj9fSII2R5xw51+04akwnCzMHKsFx3V JxDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:x-system-of-record:x-gm-message-state; bh=RhvG+EviAeorG6E8VWD3DOTWGJx0nEHA4nRkelVhWd4=; b=OKRmAf2/8KykwYMV3/sR5GD8V/Me7sYXVS63rOPYhv42Xsy99MJKYqDavPNN0v6iBi sOstdD6MA4cfMoSm3MkxHJge6FU4aamAXrAbjVPDGJg6pr1cafkIQLiz/E0JNhzmXGcJ iBKwtBzUt/wY629eFugAWqxBwUFypeCYWLfiCIFZb+IogAZ80piJwqhz7dwqZV52VGT3 nblPmo/IN7Eid6lvfDzmbEwG1AaoB45GsyhtOvTSiMhWVF10V9dcOUGEA6783EkpA6rD M6vYxO7PsytsgDzwtBZEQB8ploUJ+9CLm3YtRtTub/mcilggKffndpI1xEIOFGWYCmPd M+Yw== Received: by 10.112.82.103 with SMTP id h7mr4144834lby.50.1350940913062; Mon, 22 Oct 2012 14:21:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.62.131 with HTTP; Mon, 22 Oct 2012 14:21:32 -0700 (PDT) In-Reply-To: References: From: Joshua Marantz Date: Mon, 22 Oct 2012 17:21:32 -0400 Message-ID: Subject: Re: apr_memcache operation timeouts To: "modules-dev@httpd.apache.org" Cc: dev Content-Type: multipart/alternative; boundary=14dae9d2f2bc3c52f704ccac7111 X-System-Of-Record: true X-Gm-Message-State: ALoCoQnvHIlI2Uc5Hdta2MdmLETcwDKQRqXJ9+ckbkt0e5Q4JWze+wpsNWk0xuCwKdto7RJiddzISfJZWvKerfDFKyMC0FPwVaX2ZOr3z+2rZ4Uz6Vitj/AugV570IFGnFWLhyVJIoLGse+n0Fw9gbT+OKy4KgD/jhLrWwrNBht2tBJ3PRN1AA56mx4x3U0RCeSm6ebrWiVgHZJMnH5kcMfIsctfhoYUgw== X-Virus-Checked: Checked by ClamAV on apache.org --14dae9d2f2bc3c52f704ccac7111 Content-Type: text/plain; charset=ISO-8859-1 I've had some preliminary success with my own variant of apr_memcache.c (creatively called apr_memcache2.c). Rather than setting the socket timeout, I've been mimicing the timeout strategy I saw in apr_memcache_multgetp, by adding a new helper method: static apr_status_t wait_for_server_or_timeout(apr_pool_t* temp_pool, apr_memcache2_conn_t* conn) { apr_pollset_t* pollset; apr_status_t rv = apr_pollset_create(&pollset, 1, temp_pool, 0); if (rv == APR_SUCCESS) { apr_pollfd_t pollfd; pollfd.desc_type = APR_POLL_SOCKET; pollfd.reqevents = APR_POLLIN; pollfd.p = temp_pool; pollfd.desc.s = conn->sock; pollfd.client_data = NULL; apr_pollset_add(pollset, &pollfd); apr_int32_t queries_recvd; const apr_pollfd_t* activefds; rv = apr_pollset_poll(pollset, MULT_GET_TIMEOUT, &queries_recvd, &activefds); if (rv == APR_SUCCESS) { assert(queries_recvd == 1); assert(activefds->desc.s == conn->sock); assert(activefds->client_data == NULL); } } return rv; } And calling that before many of the existing calls to get_server_line as: rv = wait_for_server_or_timeout_no_pool(conn); if (rv != APR_SUCCESS) { ms_release_conn(ms, conn); return rv; } This is just an experiment; I think I can streamline this by pre-populating the pollfd structure as part of the apr_memcache_conn_t (actually now apr_memcache2_conn_t). I have two questions about this: 1. I noticed the version of apr_memcache.c that ships with Apache 2.4 is somewhat different from the one that ships with Apache 2.2. In particular the 2.4 version cannot be compiled against the headers that come with a 2.2 distribution. Is there any downside to taking my hacked 2.2 apr_memcache.c and running it in Apache 2.4? Or should I maintain two hacks? 2. This seems wasteful in terms of system calls. I am making an extra call to poll, rather than relying on the socket timeout. The socket timeout didn't work as well as this though. Does anyone have any theories as to why, or what could be done to the patch in https://issues.apache.org/bugzilla/show_bug.cgi?id=51065 to work? -Josh On Fri, Oct 19, 2012 at 9:25 AM, Joshua Marantz wrote: > Following up: I tried doing what I suggested above: patching that change > into my own copy of apr_memcache.c It was first of all a bad idea to pull > in only part of apr_memcache.c because that file changed slightly between > 2.2 and 2.4 and our module works in both. > > I was successful making my own version of apr_memcache (renaming > entry-points apr_memcache2*) that I could hack. But if I changed the > socket timeout from -1 to 10 seconds, then the system behaved very poorly > under load test (though it worked fine in our unit-tests and system-tests). > In other words, I think the proposed patch that Jeff pointed to above is > not really working (as he predicted). This test was done without > SIGSTOPing the memcached; it would timeout under our load anyway and > thereafter behave poorly. > > I'm going to follow up on that bugzilla entry, but for now I'm going to > pursue my own complicated mechanism of timing out the calls from my side. > > -Josh > > > On Thu, Oct 18, 2012 at 10:46 AM, Joshua Marantz wrote: > >> Thanks Jeff, that is very helpful. We are considering a course of action >> and before doing any work toward this, I'd like to understand the pitfalls >> from people that understand Apache better than us. >> >> Here's our reality: we believe we need to incorporate memcached for >> mod_pagespeed to scale effectively for very >> large sites & hosting providers. We are fairly close (we think) to >> releasing this functionality as beta. However, in such large sites, stuff >> goes wrong: machines crash, power failure, fiber cut, etc. When it does we >> want to fall back to serving partially unoptimized sites rather than >> hanging the servers. >> >> I understand the realities of backward-compatible APIs. My expectation >> is that this would take years to make it into an APR distribution we could >> depend on. We want to deploy this functionality in weeks. The workarounds >> we have tried backgrounding the apr_memcache calls in a thread and timing >> out in mainline are complex and even once they work 100% will be very >> unsatisfactory (resource leaks; Apache refusing to exit cleanly on >> 'apachectl stop') if this happens more than (say) once a month. >> >> Our plan is to copy the patched implementation of >> apr_memcache_server_connect and the static methods it calls into a new .c >> file we will link into our module, naming the new entry-point something >> else (apr_memcache_server_connect_with_timeout seems good). From a >> CS/SE perspective this is offensive and we admit it, but from a product >> quality perspective we believe this beats freezes and complicated/imperfect >> workarounds with threads. >> >> So I have two questions for the Apache community: >> >> 1. What are the practical problems with this approach? Note that in >> any case a new APR rev would require editing/ifdefing our code anyway, so I >> think immunity from APR updates such as this patch being applied is not a >> distinguishing drawback. >> 2. Is there an example of the correct solution to the technical >> problem Jeff highlighted: "it is apparently missing a call to adjust >> the socket timeout and to discard the connection if the timeout is reached". >> That sounds like a pattern that might be found elsewhere in the Apache >> HTTPD code base. >> >> Thanks in advance for your help! >> -Josh >> >> >> On Wed, Oct 17, 2012 at 8:16 PM, Jeff Trawick wrote: >> >>> On Wed, Oct 17, 2012 at 3:36 PM, Joshua Marantz >>> wrote: >>> > Is there a mechanism to time out individual operations? >>> >>> No, the socket connect timeout is hard-coded at 1 second and the >>> socket I/O timeout is disabled. >>> >>> Bugzilla bug https://issues.apache.org/bugzilla/show_bug.cgi?id=51065 >>> has a patch, though it is apparently missing a call to adjust the >>> socket timeout and to discard the connection if the timeout is >>> reached. More importantly, the API can only be changed in future APR >>> 2.0; alternate, backwards-compatible API(s) could be added in future >>> APR-Util 1.6. >>> >>> > >>> > If memcached freezes, then it appears my calls to 'get' will block >>> until >>> > memcached wakes up. Is there any way to set a timeout for that call? >>> > >>> > I can repro this in my unit tests by sending a SIGSTOP to memcached >>> before >>> > doing a 'get'? >>> > >>> > Here are my observations: >>> > >>> > apr_memcache_multgetp seems to time out in bounded time if I SIGSTOP >>> the >>> > memcached process. Yes! >>> > >>> > apr_memcache_getp seems to hang indefinitely if I SIGSTOP the memcached >>> > process. >>> > >>> > apr_memcache_set seems to hang indefinitely if I SIGSTOP the memcached >>> > process. >>> > >>> > apr_memcache_delete seems to hang indefinitely if I SIGSTOP the >>> memcached >>> > process. >>> > >>> > apr_memcache_stats seems to hang indefinitely if I SIGSTOP the >>> memcached >>> > process. >>> > >>> > That last one really sucks as I am using that to print the status of >>> all my >>> > cache shards to the log file if I detected a problem :( >>> > >>> > >>> > Why does apr_memcache_multgetp do what I want and not the others? Can >>> I >>> > induce the others to have reasonable timeout behavior? >>> > >>> > When I SIGSTOP memcached this makes it hard to even restart Apache, at >>> > least with graceful-stop. >>> > >>> > >>> > On a related note, the apr_memcache >>> > documentation< >>> http://apr.apache.org/docs/apr-util/1.4/group___a_p_r___util___m_c.html >>> >is >>> > very thin. I'd be happy to augment it with my observations on its >>> > usage >>> > and the meaning of some of the arguments if that was desired. How >>> would I >>> > go about that? >>> >>> Check out APR trunk from Subversion, adjust the doxygen docs in the >>> include files, build (make dox) and inspect the results, submit a >>> patch to dev@apr.apache.org. >>> >>> > >>> > -Josh >>> >>> >>> >>> -- >>> Born in Roswell... married an alien... >>> http://emptyhammock.com/ >>> >> >> > --14dae9d2f2bc3c52f704ccac7111--