Improve resource usage

- Only create json files from scratch if they didn't exists.
- Otherwise update them only once every $IVAL minutes
- Only remove first line and add last line.
This commit is contained in:
Jochen Hoenicke 2018-11-24 14:12:05 +01:00
parent 8d54538a61
commit ceaff66bbb
3 changed files with 64 additions and 5 deletions

View File

@ -4,20 +4,30 @@ DESTDIR=/dev/shm/mempool-btc
BITCOINCLI=/home/bitcoin/bin/bitcoin-cli
MEMPOOLHOME=/home/mempool/mempool
TMPFILE=$DESTDIR/rawdump.txt
export DESTDIR MEMPOOLHOME
mkdir -p $DESTDIR
cd $MEMPOOLHOME
# create ram-disk directory if it does not exists
if [ ! -e $DESTDIR ]; then
mkdir -p $DESTDIR/LOCK
# read mempool.log once sequentially to quickly load it in buffers
cat mempool.log > /dev/null
./mkdata.sh
rmdir $DESTDIR/LOCK
fi
# create mempool statistics, protected by LOCK
if ! mkdir $DESTDIR/LOCK 2>/dev/null; then
exit
exit
fi
$BITCOINCLI getrawmempool true > $TMPFILE
python3 mempool_sql.py < $TMPFILE
rmdir $DESTDIR/LOCK
# update ram-disk directory, protected by DATALOCK
if ! mkdir $DESTDIR/DATALOCK 2>/dev/null; then
exit
exit
fi
./mkdata.sh
./updatedata.sh
rmdir $DESTDIR/DATALOCK

View File

@ -1,5 +1,7 @@
#!/bin/bash
# create the JSON files delivering the summarized mempool
MEMPOOL=mempool.log
createfile() {

47
updatedata.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
# update the JSON files delivering the summarized mempool
#
# LINE is set to the last line in mempool.
# for each file:
# check if current minute divisible by IVAL
# if divisible:
# remove first line (after 'call([').
# add LINE to this file (before last line '])').
MEMPOOL=mempool.log
LINE=`tail -1 $MEMPOOL`
SECOND=`date +%s`
MINUTE=`expr $SECOND / 60`
updatefile() {
NAME=$1
MINUTES=$2
IVAL=$3
if [ `expr $MINUTE % $IVAL` -eq "0" ]; then
(echo 'call(['; tail -n +3 $DESTDIR/$NAME.js | head -n -1; echo "$LINE"; echo '])') > $DESTDIR/$NAME.js.new
mv $DESTDIR/$NAME.js.new $DESTDIR/$NAME.js
fi
}
updatefile_all() {
NAME=all
IVAL=$1
if [ `expr $MINUTE % $IVAL` -eq "0" ]; then
(head -n -1 $DESTDIR/$NAME.js; echo "$LINE"; echo '])') > $DESTDIR/$NAME.js.new
mv $DESTDIR/$NAME.js.new $DESTDIR/$NAME.js
fi
}
updatefile 2h 120 1
updatefile 8h 480 1
updatefile 24h 1440 1
updatefile 2d 2880 2
updatefile 4d 5760 4
updatefile 1w 10080 7
updatefile 2w 20160 14
updatefile 30d 43200 30
updatefile 3m 131040 90
updatefile 6m 262080 180
updatefile 1y 524160 360
updatefile_all 360