summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-06-02 17:20:19 -0400
committerNick Vatamaniuc <vatamane@apache.org>2020-06-02 17:31:53 -0400
commitc5397dea1ae8a0c35aa7945b888a6bf9f105dc70 (patch)
tree61e34c6ee54ecab6c8451d7c5b51d81d59e1c0d7
parentb3fe0902683af5c65813cb0623a791cd8d9b8873 (diff)
downloadcouchdb-make-couch-view-job-accepts-faster.tar.gz
Improve efficiency of couch_jobs:accept/2 for viewsmake-couch-view-job-accepts-faster
Use the `no_schedule` option to speed up job dequeuing. This optimization allows dequeuing jobs more efficiently if these conditions are met: 1) Job IDs start with a random prefix 2) No time-based scheduling is used Both of those can be true for views job IDs can be generated such that signature comes before the db name part, which is what this commit does. The way the optimization works, is random IDs are generating in pending jobs range, then, a key selection is used to pick either a job before or after it. That reduces each dequeue attempt to just 1 read instead of reading up to 1000 jobs.
-rw-r--r--src/couch_views/src/couch_views_indexer.erl3
-rw-r--r--src/couch_views/src/couch_views_jobs.erl4
-rw-r--r--src/couch_views/test/couch_views_cleanup_test.erl2
3 files changed, 6 insertions, 3 deletions
diff --git a/src/couch_views/src/couch_views_indexer.erl b/src/couch_views/src/couch_views_indexer.erl
index bd1bd4de6..4d09fdb6d 100644
--- a/src/couch_views/src/couch_views_indexer.erl
+++ b/src/couch_views/src/couch_views_indexer.erl
@@ -44,7 +44,8 @@ spawn_link() ->
init() ->
- {ok, Job, Data0} = couch_jobs:accept(?INDEX_JOB_TYPE, #{}),
+ Opts = #{no_schedule => true},
+ {ok, Job, Data0} = couch_jobs:accept(?INDEX_JOB_TYPE, Opts),
Data = upgrade_data(Data0),
#{
<<"db_name">> := DbName,
diff --git a/src/couch_views/src/couch_views_jobs.erl b/src/couch_views/src/couch_views_jobs.erl
index a9ca168ee..4b0aa2660 100644
--- a/src/couch_views/src/couch_views_jobs.erl
+++ b/src/couch_views/src/couch_views_jobs.erl
@@ -134,7 +134,9 @@ job_id(#{name := DbName}, #mrst{sig = Sig}) ->
job_id(DbName, Sig) ->
HexSig = fabric2_util:to_hex(Sig),
- <<DbName/binary, "-", HexSig/binary>>.
+ % Put signature first in order to be able to use the no_schedule
+ % couch_jobs:accept/2 option
+ <<HexSig/binary, "-", DbName/binary>>.
job_data(Db, Mrst) ->
diff --git a/src/couch_views/test/couch_views_cleanup_test.erl b/src/couch_views/test/couch_views_cleanup_test.erl
index b5e081a98..e4dcdceea 100644
--- a/src/couch_views/test/couch_views_cleanup_test.erl
+++ b/src/couch_views/test/couch_views_cleanup_test.erl
@@ -408,4 +408,4 @@ job_id(Db, DDoc) ->
DbName = fabric2_db:name(Db),
{ok, #mrst{sig = Sig}} = couch_views_util:ddoc_to_mrst(DbName, DDoc),
HexSig = fabric2_util:to_hex(Sig),
- <<DbName/binary, "-", HexSig/binary>>.
+ <<HexSig/binary, "-", DbName/binary>>.