Skip to content

Commit

Permalink
add comments to example
Browse files Browse the repository at this point in the history
  • Loading branch information
briangu committed Jan 25, 2024
1 parent fdf52d8 commit 8eb0671
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/stats_logging/stats_server.kg
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ statsT:::[:_(tbs?"stats");.table(colsFromNames(cols));tbs?"stats"]
:" Create a database so we can inspect the data "
db::.db(:{},"stats",,statsT)

:" Reading from the db will cause buffered inserts to flush into the underlying table "
syncDb::{db("select 1 from stats")}

:" Read and print the table size "
tableSize::{[q];q::db("select count(*) from stats");.d("rows: ");.p(q);q}
tableSize()

:" Periodically report write stats "
lastTime::.pc()
lastSize::0
batchSize::0
writeStats::{[n];n::.pc();.d("writes/sec: ");.p((batchSize-lastSize)%(n-lastTime));lastTime::n;lastSize::batchSize}
writeStats::{[n];n::.pc();.d("writes/sec: ");.p((batchSize-lastSize)%(n-lastTime));lastTime::n;lastSize::batchSize;1}
.timer("write stats";60;writeStats)

:" Periodically flush the table to disk "
flushTable::{tbs,"stats",statsT}
store::{:[batchSize;flushTable();0];batchSize::0;1}
store::{:[batchSize;flushTable();0];batchSize::0;lastSize::0;lastTime::.pc();1}
timeStore::{[r];r::time0(store());.d("store ms: ");.p(r)}
flush::{tableSize();timeStore();1}
.timer("flush";300;flush)
Expand Down

0 comments on commit 8eb0671

Please sign in to comment.