Files
zapdb/skl
Manish R Jain fad98504c0 Refactor compaction logic, improve logging.
Refactor compaction logic to be in-line with how RocksDB does things.
This refactoring now allows multiple compactions to happen
simultaneously, even at the same level; ensuring that the ranges being
compacted are not overlapping.

We no longer ask for verbosity of output, because all logging has now
been switched over to trace package. We use trace.Trace for compactions,
and trace.EventLog for KV and ValueLog.

The following is a log of all the individual commits.

commit 746c5118a3463483ccb41126d34a7bf35a19c686
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 15:43:07 2017 +1000

    Address comments

commit 3957d6b5d2b39b93fcd901b45ae09c5d2d04752c
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 15:29:01 2017 +1000

    Keep more events per compaction

commit e79c87f0502a6bd2ad0ba48c162d47a71e05e9e3
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 15:22:11 2017 +1000

    Remove y.Printf entirely, along with verbose mode. All logging is done via event log and tracing.

commit b0452d8c1bdd511a7bb088489637a7da035acfaa
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 15:04:47 2017 +1000

    Move compaction logs entirely to tracer

commit 28bb7cfeec1fbf59301428845cb9aa14d15cb94e
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 04:53:26 2017 +0000

    Use tracers for each compaction.

commit 71462ceaa433b9d96bab267101f4df560afa7ef5
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 11:08:17 2017 +1000

    Switch compactions to trace.Trace

commit c982b4ec81710b7ab1cbc389800a379a59ceb92b
Author: Manish R Jain <manish@dgraph.io>
Date:   Mon Jun 5 09:58:52 2017 +0000

    Move stuff to elog

commit f1883fc5594e979803cb4b9639d20bb698ad2fae
Author: Manish R Jain <manish@dgraph.io>
Date:   Fri Jun 2 19:31:41 2017 +1000

    Move compaction logs to event log

commit e86865802929e6fc996fb04f3bb8a9995a6b85fe
Author: Manish R Jain <manish@dgraph.io>
Date:   Fri Jun 2 16:21:12 2017 +1000

    Double check in compareandadd if we really need a compactino.

commit a4cf25515249188c5a16b60648b909a2cc61629c
Author: Manish R Jain <manish@dgraph.io>
Date:   Fri Jun 2 16:09:09 2017 +1000

    Try other levels if can't run compaction.

commit 3f34dca250f612557d8e17337bf5efec73c4214f
Author: Manish R Jain <manish@dgraph.io>
Date:   Thu Jun 1 18:40:38 2017 +1000

    Keep track of tables being currently compacted.

commit e9c895a64a7e942aef53300b2f605bfd91c859b9
Author: Manish R Jain <manish@dgraph.io>
Date:   Thu Jun 1 18:23:22 2017 +1000

    Run 3 compactors simultaneously

commit 9e3dfc101ac9dfb644b36d13a026062d178effe5
Author: Manish R Jain <manish@dgraph.io>
Date:   Thu Jun 1 13:52:53 2017 +1000

    Kinda works with compaction using key ranges to determine overlap.

commit c767a55ab9b30c55c0eda10e6606460bf5bac317
Author: Manish R Jain <manish@dgraph.io>
Date:   Wed May 31 19:47:09 2017 +1000

    Allow multiple compactions to happen concurrently.
2017-06-06 15:56:25 +10:00
..
2017-05-14 20:23:38 +10:00
2017-04-28 00:31:24 +08:00

This is much better than skiplist and slist.

BenchmarkReadWrite/frac_0-4         	 1000000	      1516 ns/op
BenchmarkReadWrite/frac_1-4         	 1000000	      1456 ns/op
BenchmarkReadWrite/frac_2-4         	 1000000	      1354 ns/op
BenchmarkReadWrite/frac_3-4         	 1000000	      1295 ns/op
BenchmarkReadWrite/frac_4-4         	 1000000	      1142 ns/op
BenchmarkReadWrite/frac_5-4         	 1000000	      1077 ns/op
BenchmarkReadWrite/frac_6-4         	 1000000	      1003 ns/op
BenchmarkReadWrite/frac_7-4         	 2000000	      1054 ns/op
BenchmarkReadWrite/frac_8-4         	 2000000	       929 ns/op
BenchmarkReadWrite/frac_9-4         	 3000000	       815 ns/op
BenchmarkReadWrite/frac_10-4        	 5000000	       472 ns/op

But compared to a simple map with read-write lock, it is still slower.

BenchmarkReadWriteMap/frac_0-4         	 2000000	       883 ns/op
BenchmarkReadWriteMap/frac_1-4         	 2000000	       830 ns/op
BenchmarkReadWriteMap/frac_2-4         	 2000000	       658 ns/op
BenchmarkReadWriteMap/frac_3-4         	 2000000	       662 ns/op
BenchmarkReadWriteMap/frac_4-4         	 2000000	       657 ns/op
BenchmarkReadWriteMap/frac_5-4         	 2000000	       650 ns/op
BenchmarkReadWriteMap/frac_6-4         	 3000000	       592 ns/op
BenchmarkReadWriteMap/frac_7-4         	 3000000	       573 ns/op
BenchmarkReadWriteMap/frac_8-4         	 3000000	       539 ns/op
BenchmarkReadWriteMap/frac_9-4         	 3000000	       521 ns/op
BenchmarkReadWriteMap/frac_10-4        	 3000000	       479 ns/op

Node Pooling

Command used

rm -Rf tmp && /usr/bin/time -l ./populate -keys_mil 10

For pprof results, we run without using /usr/bin/time. There are four runs below.

Results seem to vary quite a bit between runs.

Before node pooling

1311.53MB of 1338.69MB total (97.97%)
Dropped 30 nodes (cum <= 6.69MB)
Showing top 10 nodes out of 37 (cum >= 12.50MB)
      flat  flat%   sum%        cum   cum%
  523.04MB 39.07% 39.07%   523.04MB 39.07%  github.com/dgraph-io/badger/skl.(*Skiplist).Put
  184.51MB 13.78% 52.85%   184.51MB 13.78%  runtime.stringtoslicebyte
  166.01MB 12.40% 65.25%   689.04MB 51.47%  github.com/dgraph-io/badger/mem.(*Table).Put
     165MB 12.33% 77.58%      165MB 12.33%  runtime.convT2E
  116.92MB  8.73% 86.31%   116.92MB  8.73%  bytes.makeSlice
   62.50MB  4.67% 90.98%    62.50MB  4.67%  main.newValue
   34.50MB  2.58% 93.56%    34.50MB  2.58%  github.com/dgraph-io/badger/table.(*BlockIterator).parseKV
   25.50MB  1.90% 95.46%   100.06MB  7.47%  github.com/dgraph-io/badger/y.(*MergeIterator).Next
   21.06MB  1.57% 97.04%    21.06MB  1.57%  github.com/dgraph-io/badger/table.(*Table).read
   12.50MB  0.93% 97.97%    12.50MB  0.93%  github.com/dgraph-io/badger/table.header.Encode

      128.31 real       329.37 user        17.11 sys
3355660288  maximum resident set size
         0  average shared memory size
         0  average unshared data size
         0  average unshared stack size
   2203080  page reclaims
       764  page faults
         0  swaps
       275  block input operations
        76  block output operations
         0  messages sent
         0  messages received
         0  signals received
     49173  voluntary context switches
    599922  involuntary context switches

After node pooling

1963.13MB of 2026.09MB total (96.89%)
Dropped 29 nodes (cum <= 10.13MB)
Showing top 10 nodes out of 41 (cum >= 185.62MB)
      flat  flat%   sum%        cum   cum%
  658.05MB 32.48% 32.48%   658.05MB 32.48%  github.com/dgraph-io/badger/skl.glob..func1
  297.51MB 14.68% 47.16%   297.51MB 14.68%  runtime.convT2E
  257.51MB 12.71% 59.87%   257.51MB 12.71%  runtime.stringtoslicebyte
  249.01MB 12.29% 72.16%  1007.06MB 49.70%  github.com/dgraph-io/badger/mem.(*Table).Put
  142.43MB  7.03% 79.19%   142.43MB  7.03%  bytes.makeSlice
     100MB  4.94% 84.13%   758.05MB 37.41%  github.com/dgraph-io/badger/skl.newNode
   99.50MB  4.91% 89.04%    99.50MB  4.91%  main.newValue
      75MB  3.70% 92.74%       75MB  3.70%  github.com/dgraph-io/badger/table.(*BlockIterator).parseKV
   44.62MB  2.20% 94.94%    44.62MB  2.20%  github.com/dgraph-io/badger/table.(*Table).read
   39.50MB  1.95% 96.89%   185.62MB  9.16%  github.com/dgraph-io/badger/y.(*MergeIterator).Next

      135.58 real       374.29 user        17.65 sys
3740614656  maximum resident set size
         0  average shared memory size
         0  average unshared data size
         0  average unshared stack size
   2276566  page reclaims
       770  page faults
         0  swaps
       128  block input operations
        90  block output operations
         0  messages sent
         0  messages received
         0  signals received
     46434  voluntary context switches
    597049  involuntary context switches