Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 31137 invoked from network); 15 Mar 2010 19:51:29 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Mar 2010 19:51:29 -0000 Received: (qmail 22359 invoked by uid 500); 15 Mar 2010 19:50:41 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 22326 invoked by uid 500); 15 Mar 2010 19:50:41 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 22318 invoked by uid 99); 15 Mar 2010 19:50:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Mar 2010 19:50:41 +0000 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [72.14.220.155] (HELO fg-out-1718.google.com) (72.14.220.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Mar 2010 19:50:35 +0000 Received: by fg-out-1718.google.com with SMTP id 19so1340107fgg.5 for ; Mon, 15 Mar 2010 12:50:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.239.191.199 with SMTP id c7mr454766hbi.205.1268682613499; Mon, 15 Mar 2010 12:50:13 -0700 (PDT) In-Reply-To: References: <2fc10a851003151223w38dabf3etda6132a4a617b032@mail.gmail.com> Date: Mon, 15 Mar 2010 12:50:11 -0700 Message-ID: <2fc10a851003151250w39ed6a6fy351b3f891a136c77@mail.gmail.com> Subject: Re: Performance when sending array of keys to a view From: Nick Poulden To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=001485f875ba82aa1d0481dc30b8 --001485f875ba82aa1d0481dc30b8 Content-Type: text/plain; charset=ISO-8859-1 After further investigation the problem was with the CouchDB node plugin. Using pure node.js it's nice and fast. Thanks for the help :-) Nick On Mon, Mar 15, 2010 at 12:33 PM, Paul Davis wrote: > When you post a keys array its doing a search through the view btree > to get each key. Where as with limit=20, it's searching once and then > scanning linearly. > > What happens if you sort the array of keys before posting them? > > On Mon, Mar 15, 2010 at 3:23 PM, Nick Poulden wrote: > > Hi, > > > > I'm developing a web app with node.js and CouchDB that displays nearby > > restaurants when given a lat/lng. At the moment I'm storing the > restaurant > > data in CouchDB and a MySQL table with couchdb-key / lat / lng for each > > restaurant. I query MySQL for the nearby restaurants, then do a POST to a > > CouchDB view with the keys returned by MySQL. > > > > The problem is that there seems to be a huge difference in performance > when > > sending the list of keys compared to a 'normal' view query. > > > > Here's an example: > > > > var db = CouchDB.db('restaurants'); > > profiles.push(["Before Couch request: ", Number(new Date)]) > > db.view('Restaurant/by_idx', {keys: restaurant_keys, include_docs: true, > > success: function(response) { > > profiles.push(["After couch result: ", Number(new Date)]) > > }}); > > > > Start: 0 ms > > Before MySQL connect: 0 ms > > Got MySQL result: 17 ms > > Before Couch request: 18 ms > > After couch result: 272 ms > > > > If I replace line 3 with this: > > > > db.view('Restaurant/by_idx', {limit: 20, include_docs: true, success: > > function(response) { > > > > I get this: > > > > Start: 0ms > > Before MySQL connect: 0 ms > > Got MySQL result: 12 ms > > Before Couch request: 13 ms > > After couch result: 21 ms > > > > In both cases there are about 20 restaurants returned. The database has > > about 500 documents in it altogether. Can anyone shed some light on why > > there is such a big difference in response time? > > > > Thanks, > > > > Nick > > > --001485f875ba82aa1d0481dc30b8--