Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DB83BDFE2 for ; Thu, 12 Jul 2012 07:54:11 +0000 (UTC) Received: (qmail 13536 invoked by uid 500); 12 Jul 2012 07:54:11 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 13298 invoked by uid 500); 12 Jul 2012 07:54:11 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 13264 invoked by uid 99); 12 Jul 2012 07:54:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2012 07:54:10 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bchesneau@gmail.com designates 74.125.83.52 as permitted sender) Received: from [74.125.83.52] (HELO mail-ee0-f52.google.com) (74.125.83.52) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2012 07:54:02 +0000 Received: by eeke53 with SMTP id e53so609829eek.11 for ; Thu, 12 Jul 2012 00:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=2CAqDseL0xiViXmVywvxCPPWdzMxHRKGiEoHLPmMK98=; b=l0kgF0fHA9TCNizDxSFslXGoOLzk6fkdylMqtlJu6VO7kpbVAMrjyKLDF7aCrBMMgr jVtiqf/AGu+rgM8fcItLQibaRYi3XyIOIwbr7UkeVF+Be4LxPR+oRfXrj4PHxNHaEJf4 eu6q6MiSDCiBq3I1UPG/UC2m1/ZZsk+cutL42mKEfu5fTU1dLDPKRA4a0W5ex7c8Qqqm YILaLJb+WIpB5kSafflplWS6iK6QIvITM3KQwMzIJAw/GWf4DRBkbrOrSkaFs4r2ZCFD u+fm1k6YlqPGDB5isZ/a4d1JnTpz6Mbf6sy8GzAomWI6alg1ZUJC4jFYyZHzYRsvgrx2 WYzw== MIME-Version: 1.0 Received: by 10.14.188.129 with SMTP id a1mr12311586een.183.1342079622276; Thu, 12 Jul 2012 00:53:42 -0700 (PDT) Received: by 10.14.4.200 with HTTP; Thu, 12 Jul 2012 00:53:42 -0700 (PDT) In-Reply-To: References: Date: Thu, 12 Jul 2012 09:53:42 +0200 Message-ID: Subject: Re: couch_query_server refactoring From: Benoit Chesneau To: dev@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, Jul 12, 2012 at 9:23 AM, Paul Davis w= rote: > I actually see one of two ways. And which one we go with depends on > and odd question that I've never really asked (or seen discussed) > before. > > Both patterns would have a single couchjs process that is threaded and > can respond to multiple requests simultaneously. Doing this gives us > an ability to maximize throughput using pipelining and the like. The > downfall is that if the couchjs process dies then it affects every > other message that was in transit through it. Although I think we can > mitigate a lot of this with some basic retry/exponential back off > logic. > > One way we can do this is to use a similar approach to what we do now > but asyncronously. Ie, messages from Erlang to couchjs become tagged > tuples that a central process dispatches back and forth to clients. > There are a few issues here. Firstly, we're going to basically need > two caches of lookups which could be harmful to low latency > requirements. Ie, Erlang will have to keep a cache of tag/client > pairs, and the couchjs side will have to have some sort of lookup > table/cache thing for ddoc ids to JS_Contexts. The weird question I > have about this is, "What is the latency/bandwidth of stdio?" I've > never thought to try and benchmark such a thing but it seems possible > (no idea how likely though) that we could max out the capacity of a > single file descriptor for communication. > > The second approach is to turn couchjs into a simple threaded network > server. This way the Erlang side would just open a socket per design > doc/context pair, and the couchjs side would be rather simple to > implement (considering the alternative). I like this approach because > it minimizes cache/lookups, uses more file descriptors (not sure if > this is a valid concern), and (most importantly) keeps most of the > complexity in Erlang where its easier to manage. I quite like this second approach too. It would ease any implementation and is also really portable. Ie passing a socket path or port to an external server is easier in that case. For example on IOS the app accessing to couchdb could maintain this process internally and won't break any sandbox. It may be easier than writing a nif for each cases... > > Either way, once either of those things is implemented we can > re-implement our external process management to not totally bork > servers under load as well as (hopefully) improve latency considerably > for any of our "RPC" things. you mean the pool of couch_os_processes ? - beno=EEt