From 33f38144eb5cb969ce27bf11ac6152d9f49ff366 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 23 Oct 2020 07:32:54 +0100 Subject: [PATCH] record the number of connections in the db every minute. Gitlab issue #49 --- .../main/groovy/com/muwire/core/MuWireSettings.groovy | 7 +++++++ .../groovy/com/muwire/core/hostcache/DB2CSV.groovy | 4 ++++ .../com/muwire/core/hostcache/H2HostCache.groovy | 11 ++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index 92f1ac86..c3a897bc 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -43,6 +43,7 @@ class MuWireSettings { int peerConnections int leafConnections + int connectionHistory int responderCacheSize @@ -118,6 +119,9 @@ class MuWireSettings { leafConnections = Integer.valueOf(props.getProperty("leafConnections","512")) peerConnections = Integer.valueOf(props.getProperty("peerConnections","128")) + // connection stats history + connectionHistory = Integer.valueOf(props.getProperty("connectionHistory","1024")) + // responder cache settings responderCacheSize = Integer.valueOf(props.getProperty("responderCacheSize","32")) @@ -195,6 +199,9 @@ class MuWireSettings { props.setProperty("peerConnections", String.valueOf(peerConnections)) props.setProperty("leafConnections", String.valueOf(leafConnections)) + // connection history + props.setProperty("connectionHistory", String.valueOf(connectionHistory)) + // responder cache settings props.setProperty("responderCacheSize", String.valueOf(responderCacheSize)) diff --git a/core/src/main/groovy/com/muwire/core/hostcache/DB2CSV.groovy b/core/src/main/groovy/com/muwire/core/hostcache/DB2CSV.groovy index 1fbf6df4..3e965fb4 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/DB2CSV.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/DB2CSV.groovy @@ -33,6 +33,10 @@ class DB2CSV { println "${dest.toBase32()},$it.SS,$it.SR,$it.SF,$it.RS,$it.RR,$it.RF,$it.FS,$it.FR,$it.FF" } break + case "CONNECTION_COUNT" : + sql.eachRow("select * from CONNECTION_COUNT") { + println "$it.TSTAMP, $it.COUNT" + } } sql.close() } diff --git a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy index ae29e7f0..20f1a251 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy @@ -259,7 +259,7 @@ class H2HostCache extends HostCache { log.info("created table attempts $success") // TODO add primary key - success = sql.execute("CREATE TABLE IF NOT EXISTS HOST_PROFILES(" + + success &= sql.execute("CREATE TABLE IF NOT EXISTS HOST_PROFILES(" + "DESTINATION VARCHAR(1024)," + "SS VARCHAR(16)," + "SR VARCHAR(16)," + @@ -272,6 +272,7 @@ class H2HostCache extends HostCache { "FF VARCHAR(16)" + ")") + success &= sql.execute("CREATE TABLE IF NOT EXISTS CONNECTION_COUNT(TSTAMP TIMESTAMP, COUNT INT)") timer.schedule({load()} as TimerTask, 1) } @@ -319,6 +320,7 @@ class H2HostCache extends HostCache { timer.schedule({ purgeHopeless() verifyHosts() + recordConnectionCount() } as TimerTask, 60000, 60000) loaded = true } @@ -385,4 +387,11 @@ class H2HostCache extends HostCache { } + private synchronized void recordConnectionCount() { + int count = connSupplier.get().size() + def tstamp = SDF.format(new Date()) + sql.execute("insert into CONNECTION_COUNT values('$tstamp','$count')") + sql.execute("delete from CONNECTION_COUNT where TSTAMP not in (select TSTAMP from CONNECTION_COUNT order by TSTAMP desc limit ${settings.connectionHistory})") + } + } \ No newline at end of file