Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6543513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:21:21+00:00 2026-05-25T11:21:21+00:00

I have a CouchDB database with documents representing 100,000 events. Each event has, among

  • 0

I have a CouchDB database with documents representing 100,000 events. Each event has, among other things, a time that it took place (stored as an array of [Year,month,day,hour,minute,second]) and a score. I would like to make a graph of average scores over time. In order to do this, I created a view with a map that emitted keys bucketed into intervals, and a reduce function that averaged keys in a bucket.

This works quite well. When queried for the total average, CouchDB returns a result almost instantly. When I bucket by day and get a hundred or so results, my CouchDB database takes a couple hundred ms to produce a result. Using 1000+ buckets, a query takes several seconds to return. While this query is running, my CPU jumps to 100% and my disk is fairly quiet.

I am a bit puzzled by this slowdown. Since reducing over everything seems to be instant, I have concluded that the overhead may be in producing a JSON document with 1000+ entries. Is CouchDB not capable of returning 1000 result rows in a speedy fashion?

I’m a bit of a CouchDB newbie, so it’s completely possible my map or reduce function is awful, or maybe there’s a flag somewhere in the configuration that allows CouchDB to make use of more memory. Or maybe it’s the case that CouchDB is simply strongly optimized for aggregate querying over returning many results.

Advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:21:22+00:00Added an answer on May 25, 2026 at 11:21 am

    If when you say ‘average’ you mean ‘mean average’, there’s no way to get that directly with a map/reduce pair as it’s recursive (each level of recursion will introduce rounding errors).

    A better solution is to collect the sum and count of items, and you can then trivially derive the mean average on the client.

    It sounds like your reduce function is the cause of the slowdown, but I can’t tell until you show it.

    Assuming your map function is this;

    function(doc) {
      emit([doc.year, doc.month, doc.day, doc.hour, doc.minute, doc.second], doc.score);
    }
    

    and your reduce function is;

    _stats
    

    then your results should be very fast (and scalable). The built-in _stats function will return results like this;

    {"sum":2,"count":2,"min":1,"max":1,"sumsqr":2}
    

    So, for any call to your view, you can get the sum of the scores and the number of the scores, the mean average is easily derived.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CouchDB database in production. One of the documents has been edited
I have a couchdb database containing different types of documents. Unfortunately some of those
Given that I have some number of documents in my CouchDB database, I would
I have create CouchDB database with documents that have slash (/) in the document
I have a python program that accesses a couchDB database, creates new documents and
i have a database in couchdb which contain 4 documents... here the sample and
Lets say I have two types of documents stored in my CouchDB database. First
I have some couchDB database. and i want, as in mongodb , find one
Let's say I have blog entries like these in my CouchDB database: {name:Mary, postdate:20110412,
I am new to CouchDB way of making things. So, I have a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.