storj-archived/core

Used space query opens all kfs leveldb

Closed this issue · 2 comments

Package Versions

root@storj:~# npm list -g kfs
/usr/local/lib
└─┬ storjshare-daemon@2.4.4
  └─┬ storj-lib@6.2.1
    └── kfs@3.1.2
v6.10.0

Expected Behavior

A few leveldb open at the same time. Cache the size of the leveldb and update the cache on change. On receiving a contract offer use the cache to get the used space. Don't open all leveldb on every contract offer.

Actual Behavior

Please describe the program's actual behavior. Please include any stack traces
or log output in the back ticks below.

All kfs leveldb open one by one.

root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
350
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
398
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
427
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
450
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
469
root@storj:~# grep 'download\|upload\|contract offer' .storjshare/storjshare/logs/188071ba7cfd974a9e47b59e24b0737ebf845db3.log
{"level":"debug","message":"received contract offer...","timestamp":"2017-02-28T16:16:01.155Z"}
{"level":"debug","message":"received contract offer...","timestamp":"2017-02-28T16:16:14.497Z"}
{"level":"debug","message":"received contract offer...","timestamp":"2017-02-28T16:16:24.483Z"}
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
637
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
689
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
736
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
1028

Steps to Reproduce

Please include the steps the reproduce the issue, numbered below. Include as
much detail as possible.

  1. Start farming
  2. grep 'contract offer' .storjshare/storjshare/logs/188071ba7cfd974a9e47b59e24b0737ebf845db3.log
  3. ls -l /proc/416/fd | grep 'storjshare' | wc -l

Storj is using Btable#stat() inefficiently. It never calls it with the file key (which will only open the single Sbucket the corresponds to that key), so instead it measures the entire store, opening all of the buckets as you observed.
storj-archived/kfs#48 (comment)

Retest looks awesome:

root@storj:~# grep 'download\|upload\|contract offer' .storjshare/storjshare/logs/188071ba7cfd974a9e47b59e24b0737ebf845db3.log
{"level":"debug","message":"received contract offer...","timestamp":"2017-03-01T23:03:12.087Z"}
{"level":"debug","message":"received contract offer...","timestamp":"2017-03-01T23:03:47.298Z"}
{"level":"debug","message":"received contract offer...","timestamp":"2017-03-01T23:05:40.132Z"}
root@storj:~# ls -l /proc/416/fd | grep 'storjshare' | wc -l
8