konrad-ohms opened a new issue #3517:
URL: https://github.com/apache/couchdb/issues/3517


   I was trying to upgrade my database installation from CouchDB v2.3.1 to 
v3.1.1 and experienced about 6 time slower performance on particular view 
invocations.
   
   ## Description
   
   [NOTE]: # ( Describe the problem you're encountering. )
   [TIP]:  # ( Do NOT give us access or passwords to your actual CouchDB! )
   
   ## Steps to Reproduce
   To make it easier to reproduce, I created a script which sets up CouchDB 
2.3.1 and CouchDB 3.1.1 in docker/podman, generates example data and imports 
the problematic view.
   The test script generates 12000 documents and a single design document 
including the slow view.
   The script can be used to measure response times against the local system.
   
   
[2021_04_19-couchdb-test.zip](https://github.com/apache/couchdb/files/6337054/2021_04_19-couchdb-test.zip)
   
   ## Show usage
   ```
   $ ./couchdb-test.sh 
   Usage: couchdb-test.sh setup|query|cleanup
   ```
   
   ## Initial setup of scenario to reproduce
   The following step takes about 13 min to run, the data generation is not 
very efficient with curl, but I did not want to force to much requirements on 
the host except of having bash, curl and docker/podman installed.
   ```
   $ ./couchdb-test.sh setup
   CouchDB performance regression test script
   Initializing clean CouchDB setups
   Cleanup containers if present
   Error: failed to evict container: "": failed to find container "couchdb2" in 
state: no container with name or ID couchdb2 found: no such container
   Create container
   e0077b6673c9751053d4c9613c38c5de0015a283315a3dd4f125a6242de835af
   Cleanup containers if present
   Error: failed to evict container: "": failed to find container "couchdb3" in 
state: no container with name or ID couchdb3 found: no such container
   Create container
   d114d4a2e6eb28f8f322e85083e46aa033701206a13c1789c6beccc8d457f656
   Setup CouchDB2
   Waiting for CouchDB2 to become available at http://localhost:3002...
   CouchDB is up and running
   Creating _users
   {"ok":true}
   Creating _replicator
   {"ok":true}
   Creating _global_changes
   {"ok":true}
   Creating demo
   {"ok":true}
   Setup CouchDB3
   Waiting for CouchDB2 to become available at http://localhost:3003...
   CouchDB is up and running
   Creating _users
   {"ok":true}
   Creating _replicator
   {"ok":true}
   Creating _global_changes
   {"ok":true}
   Creating demo
   {"ok":true}
   Creating design doc
   {"ok":true,"id":"_design/demo","rev":"1-6732411a147da115d79425ba6aeb71de"}
   Creating design doc
   {"ok":true,"id":"_design/demo","rev":"1-6732411a147da115d79425ba6aeb71de"}
   Generating data
   inserting docs cycle 1/2000
   
{"ok":true,"id":"5d933844b700c58fc1b422deb0000687","rev":"1-8353a76e296fb10a71bfb93b7b0ae73f"}
   
{"ok":true,"id":"5d933844b700c58fc1b422deb0000cf3","rev":"1-60f7912abd240b2433b1ea010f0699c4"}
   
{"ok":true,"id":"5d933844b700c58fc1b422deb0001801","rev":"1-1a83628882bcb89401df77e7fcc42fd1"}
   
{"ok":true,"id":"5d933844b700c58fc1b422deb0002000","rev":"1-8a91cdc871ffb7623369ab81d2b6e980"}
   
{"ok":true,"id":"5d933844b700c58fc1b422deb00023ce","rev":"1-66ac9947820d8f32ca321a91d11b8794"}
   ...
   inserting docs cycle 1999/2000
   
{"ok":true,"id":"01594d00a265804fd144a3e55575806e","rev":"1-6620f7ce5b499af7486ba404b43fcf6a"}
   
{"ok":true,"id":"01594d00a265804fd144a3e555758337","rev":"1-6595ca907b8e04dd56f83c56a1ccb5ee"}
   
{"ok":true,"id":"01594d00a265804fd144a3e5557584f1","rev":"1-31bfdc81ae9ab7c8d5eb16007f479309"}
   
{"ok":true,"id":"01594d00a265804fd144a3e555758f9e","rev":"1-b3109111048a9a14bce96b1a6a5df642"}
   
{"ok":true,"id":"01594d00a265804fd144a3e555759188","rev":"1-37fc4bd5012c2e90c13324cc7911d053"}
   
{"ok":true,"id":"01594d00a265804fd144a3e555759880","rev":"1-7457236eacd2fc5742491a431bccabdb"}
   inserting docs cycle 2000/2000
   
{"ok":true,"id":"01594d00a265804fd144a3e55575a0a7","rev":"1-f7fac9a3f6ce538d67747271336211c4"}
   
{"ok":true,"id":"01594d00a265804fd144a3e55575ab65","rev":"1-7e3d2b01acbc416b60e6e5be050dd790"}
   
{"ok":true,"id":"01594d00a265804fd144a3e55575b4de","rev":"1-c959b425a724ad6346f646d8a63da6cd"}
   
{"ok":true,"id":"01594d00a265804fd144a3e55575c456","rev":"1-d8bd0d00d0b04b52796cfe73d9a80760"}
   
{"ok":true,"id":"01594d00a265804fd144a3e55575cbcb","rev":"1-24f6bc4fcfdceae7ff2fae47a68fbf42"}
   
{"ok":true,"id":"01594d00a265804fd144a3e55575d758","rev":"1-b0dfc903b7f27dc98130c8d51931f5d4"}
   ```
   ## Query performance
   ```
   $ ./couchdb-test.sh query
   CouchDB performance regression test script
   Assuming that setup is already complete
   ================ Query CouchDB 2.3.1 ================
   
{"couchdb":"Welcome","version":"2.3.1","git_sha":"c298091a4","uuid":"9772359d7167d42054df2c9bca1388c9","features":["pluggable-storage-engines","scheduler"],"vendor":{"name":"The
 Apache Software Foundation"}}
   Query Database views on port 3002
   Round: 1/10
   
   real 0m6.258s
   user 0m0.013s
   sys  0m0.012s
   Round: 2/10
   
   real 0m6.526s
   user 0m0.014s
   sys  0m0.011s
   Round: 3/10
   
   real 0m6.477s
   user 0m0.010s
   sys  0m0.015s
   Round: 4/10
   
   real 0m6.156s
   user 0m0.011s
   sys  0m0.014s
   Round: 5/10
   
   real 0m6.185s
   user 0m0.015s
   sys  0m0.011s
   Round: 6/10
   
   real 0m6.082s
   user 0m0.015s
   sys  0m0.015s
   Round: 7/10
   
   real 0m5.932s
   user 0m0.012s
   sys  0m0.014s
   Round: 8/10
   
   real 0m5.594s
   user 0m0.013s
   sys  0m0.013s
   Round: 9/10
   
   real 0m6.258s
   user 0m0.012s
   sys  0m0.014s
   Round: 10/10
   
   real 0m5.796s
   user 0m0.009s
   sys  0m0.017s
   ================ Query CouchDB 3.1.1 ================
   
{"couchdb":"Welcome","version":"3.1.1","git_sha":"ce596c65d","uuid":"5f8a19fe389af901b8044f541b0d3c9f","features":["access-ready","partitioned","pluggable-storage-engines","reshard","scheduler"],"vendor":{"name":"The
 Apache Software Foundation"}}
   Query Database views on port 3003
   Round: 1/10
   
   real 0m42.177s
   user 0m0.012s
   sys  0m0.016s
   Round: 2/10
   
   real 0m39.650s
   user 0m0.013s
   sys  0m0.016s
   Round: 3/10
   
   real 0m40.073s
   user 0m0.013s
   sys  0m0.014s
   Round: 4/10
   
   real 0m40.407s
   user 0m0.011s
   sys  0m0.017s
   Round: 5/10
   
   real 0m39.927s
   user 0m0.013s
   sys  0m0.015s
   Round: 6/10
   
   real 0m38.747s
   user 0m0.012s
   sys  0m0.016s
   Round: 7/10
   
   real 0m38.286s
   user 0m0.014s
   sys  0m0.013s
   Round: 8/10
   
   real 0m38.962s
   user 0m0.015s
   sys  0m0.014s
   Round: 9/10
   
   real 0m37.821s
   user 0m0.017s
   sys  0m0.012s
   Round: 10/10
   
   real 0m37.505s
   user 0m0.015s
   sys  0m0.013s
   
   ``` 
   
   ## Cleanup
   ```
   $ ./couchdb-test.sh cleanup
   CouchDB performance regression test script
   CONTAINER ID  IMAGE                            COMMAND               CREATED 
       STATUS            PORTS                   NAMES
   b885253d64ea  docker.io/library/couchdb:3.1.1  /opt/couchdb/bin/...  2 
minutes ago  Up 2 minutes ago  0.0.0.0:3003->5984/tcp  couchdb3
   908b29168c7e  docker.io/library/couchdb:2.3.1  /opt/couchdb/bin/...  2 
minutes ago  Up 2 minutes ago  0.0.0.0:3002->5984/tcp  couchdb2
   Removing containers couchdb2 and couchdb3 if present
   908b29168c7e35b6a0dda9d2723c54ff972e44b8467ccd05b28421d033c48a9d
   b885253d64ea11a40cbb2401d4f9e04d6a34cdffcf375c37eb989d19a4f9db3f
   CONTAINER ID  IMAGE   COMMAND  CREATED  STATUS  PORTS   NAMES
   
   $ podman rmi docker.io/library/couchdb:2.3.1 docker.io/library/couchdb:3.1.1
   ```
   
   ## Expected Behaviour
   The performance of the view should not decrease, or at least not at that 
magnitude.
   
   ## Your Environment
   
   
   * CouchDB version used: v2.3.1 and v3.1.1
   * Browser name and version: curl
   * Operating system and version: I was running the script on RHEL 8.3 with 
podman version 2.2.1.
   
   ## Additional Context
   Used map function:
   ```
   function (doc) {
       if(doc.object === "ainst" && doc.result) {
           var subscription = doc.subscription || doc.tenant;
           var stats = {
               successfulCount : 0,
               failedCount : 0,
               canceledCount : 0,
               executingCount : 0,
               unsuccessfulCount : 0,
               unknownCount : 0,
               totalCount : 1,
               execTimeSum : 0,
               execTimeCount : 0,
               execTimeMin : Infinity,
               execTimeMax : 0
           }
   
           if (doc.result.status === "successful") {
               stats.successfulCount = 1;
   
               if (doc.result.executionTime) {
                   stats.execTimeSum = doc.result.executionTime;
                   stats.execTimeCount = 1;
                   stats.execTimeMin = doc.result.executionTime;
                   stats.execTimeMax = doc.result.executionTime;
               }
           } else if (doc.result.status === "failed") {
               stats.failedCount = 1;
           } else if (doc.result.status === "canceled") {
               stats.canceledCount = 1;
           } else if (doc.result.status === "executing") {
               stats.executingCount = 1;
           } else if (doc.result.status === "unsuccessful") {
               stats.unsuccessfulCount = 1;
           } else if (doc.result.status === "unknown") {
               stats.unknownCount = 1;
           }
   
           emit([subscription, doc.aDefId], stats);
       }
   }
   ```
   
   Custom reduce function:
   ```
   function (keys, values, rereduce) {
       var stats = {
           successfulCount : 0,
           failedCount : 0,
           canceledCount : 0,
           executingCount : 0,
           unsuccessfulCount : 0,
           unknownCount : 0,
           totalCount : 0,
           execTimeSum : 0,
           execTimeCount : 0,
           execTimeMin : Infinity,
           execTimeMax : 0
       }
   
       for (var index in values) {
           stats.successfulCount += values[index].successfulCount;
           stats.failedCount += values[index].failedCount;
           stats.canceledCount += values[index].canceledCount;
           stats.executingCount += values[index].executingCount;
           stats.unsuccessfulCount += values[index].unsuccessfulCount;
           stats.unknownCount += values[index].unknownCount;
           stats.totalCount += values[index].totalCount;
           if (values[index].execTimeCount) {
               stats.execTimeSum += values[index].execTimeSum;
               stats.execTimeCount += values[index].execTimeCount;
               stats.execTimeMin = Math.min(stats.execTimeMin, 
values[index].execTimeMin);
               stats.execTimeMax = Math.max(stats.execTimeMax, 
values[index].execTimeMax);
           }
       }
   
       return stats;
   }
   ```
   
   It might be related to the change in the JavaScript engine in CouchDB 3.0, 
but I am just guessing 
https://blog.couchdb.org/2020/02/26/the-road-to-couchdb-3-0-update-to-javascript-engine/
   
   Thanks in advance for any help
   Konrad


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to