Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 01F9D981A for ; Mon, 16 Apr 2012 20:41:46 +0000 (UTC) Received: (qmail 46415 invoked by uid 500); 16 Apr 2012 20:41:44 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 46368 invoked by uid 500); 16 Apr 2012 20:41:44 -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 46359 invoked by uid 99); 16 Apr 2012 20:41:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Apr 2012 20:41:44 +0000 X-ASF-Spam-Status: No, hits=0.0 required=5.0 tests=SPF_PASS,T_TVD_MIME_EPI X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [128.200.36.30] (HELO translab.its.uci.edu) (128.200.36.30) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Apr 2012 20:41:37 +0000 Received: from translab.its.uci.edu (localhost.localdomain [127.0.0.1]) by translab.its.uci.edu (8.13.1/8.12.10) with ESMTP id q3GKf81E005842 for ; Mon, 16 Apr 2012 13:41:08 -0700 Received: (from jmarca@localhost) by translab.its.uci.edu (8.13.1/8.13.1/Submit) id q3GKf8ST005841 for user@couchdb.apache.org; Mon, 16 Apr 2012 13:41:08 -0700 Date: Mon, 16 Apr 2012 13:41:08 -0700 From: James Marca To: user@couchdb.apache.org Subject: Re: Reduce just N rows? Message-ID: <20120416204108.GE29414@translab.its.uci.edu> Mail-Followup-To: user@couchdb.apache.org References: <20120415061323.GD8135@translab.its.uci.edu> <20120416192525.GC29414@translab.its.uci.edu> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bi5JUZtvcfApsciF" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i X-ITS-MailScanner-Information: Please contact the ISP for more information X-ITS-MailScanner: Found to be clean X-ITS-MailScanner-From: jmarca@translab.its.uci.edu X-ITS-Spam-Status: No --bi5JUZtvcfApsciF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 16, 2012 at 11:12:04PM +0300, Alon Keren wrote: > On 16 April 2012 22:25, James Marca wrote: >=20 > > On Sun, Apr 15, 2012 at 12:00:38PM +0300, Alon Keren wrote: > > > On 15 April 2012 09:13, James Marca wro= te: > > > ... > > > > Also, I really don't think there is any load at all on the CPU with > > this approach. Or to be more accurate, no more than any active > > database processing a view. Again apologies for stating the obvious, > > but CouchDB does incremenal updates of views, so if you keep adding > > data, it only processes the new data. Once you have processed the > > data into a view, querying it (without reduce) takes almost no CPU. > > Reducing it can be expensive if you do something in JavaScript, but > > isn't as expensive if you stick with the built in native Erlang reduce > > functions (sum, count, etc). > > >=20 > Reduces in couchdb should be incremental, unlike when doing them outside = of > couch. >=20 Just to clarify what I mean, tes the reduces are incremental, but what I mean by expensive is the cost of serializing data to JSON, processing javascript, return to Erlang. Reducing will do that at least once as far as I understand, and sometimes more if the query falls across tree boundaries. for you, ten documents/rows is probably cheap. For me, with 120 large docs per hour per detector, it gets expensive. But if you stick with _sum type functions, you don't pay for the serialization to JSON/JavsScript and back again. http://wiki.apache.org/couchdb/Performance#Erlang_implementations_of_common= _JavaScript_functions http://wiki.apache.org/couchdb/Built-In_Reduce_Functions For your case, you might try the _stats function on that second page Although that wiki page is old, it is still in the code: src/couchdb/couch_query_servers.erl. Also, I prefer _sum and _count over _stats because you can pass in lists of numbers, not just single numbers. My views dump arrays of numbers, and _sum does the right thing and produces an array of sums. Stats does not produce an array of arrays, sadly. James --bi5JUZtvcfApsciF Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (GNU/Linux) iD8DBQFPjIPk+t/6L/9qydcRAl1MAJ4jQ5cxudP0iKxJUYHkijV53GcvuQCeJ2+2 eFITbJyfojLEGMboME210sc= =JKlq -----END PGP SIGNATURE----- --bi5JUZtvcfApsciF-- -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.