-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.comment("****") | ||
|
||
|
||
**** | ||
|
||
.py("util.py") | ||
|
||
cli::.cli(8888) | ||
|
||
:" create a dictionary mapped sensor udpate " | ||
dsensor::{[d];d:::{};d,"t",now();d,"n",,"temp";d,"v",(.rn()*100)} | ||
|
||
:" create a raw sensor update " | ||
sensor::{now(),1,(.rn()*100)} | ||
|
||
:" send a batch of sensor updates " | ||
send::{cli(:rupdate,,({sensor()}'!100000));1} | ||
|
||
.timer("update";0;send) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.comment("****") | ||
|
||
A simple stats server that collects stats from clients. | ||
|
||
|
||
|
||
The database is flushed to disk periodically. | ||
|
||
**** | ||
|
||
.py("klongpy.db") | ||
|
||
:" function timing utility " | ||
time0::{[t0];t0::.pc();x@[];.pc()-t0} | ||
|
||
:" open the tables key-value store " | ||
tbs::.tables("/tmp/tables/stats") | ||
|
||
:" Load or create a new table with stats columns " | ||
cols::["t" "n" "v"] | ||
colsFromData::{{(x@0),,[]}'x} | ||
colsFromNames::{{x,,[]}'x} | ||
statsT:::[:_(tbs?"stats");.table(colsFromNames(cols));tbs?"stats"] | ||
|
||
:" Create a database so we can inspect the data " | ||
db::.db(:{},"stats",,statsT) | ||
|
||
syncDb::{db("select 1 from stats")} | ||
tableSize::{[q];q::db("select count(*) from stats");.d("rows: ");.p(q);q} | ||
tableSize() | ||
|
||
lastTime::.pc() | ||
lastSize::0 | ||
batchSize::0 | ||
writeStats::{[n];n::.pc();.d("writes/sec: ");.p((batchSize-lastSize)%(n-lastTime));lastTime::n;lastSize::batchSize} | ||
.timer("write stats";60;writeStats) | ||
|
||
flushTable::{tbs,"stats",statsT} | ||
store::{:[batchSize;flushTable();0];batchSize::0;1} | ||
timeStore::{[r];r::time0(store());.d("store ms: ");.p(r)} | ||
flush::{tableSize();timeStore();1} | ||
.timer("flush";300;flush) | ||
|
||
:" Called by clients to add new data to the server " | ||
update::{{[u];u::x;.insert(statsT;{u?x}'cols)}'x} | ||
|
||
:" Raw bulk update (without column mapping) " | ||
rupdate::{.insert(statsT;x);batchSize::batchSize+#x} | ||
|
||
:" Start the IPC server so clients can connect and add data (via update) " | ||
.srv(8888) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from datetime import datetime | ||
|
||
import pytz | ||
|
||
|
||
def now(): | ||
return datetime.now().astimezone(pytz.utc).timestamp() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.py("klongpy.db") | ||
|
||
a::[1 2 3] | ||
b::[2 3 4] | ||
c::[3 4 5] | ||
|
||
e::[] | ||
e::e,,"a",,a | ||
e::e,,"b",,b | ||
e::e,,"c",,c | ||
T::.table(e) | ||
|
||
db::.db(:{},"T",,T) | ||
|
||
t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5]]) | ||
|
||
.insert(T; [[4 5 6] [7 8 9]]) | ||
|
||
t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6] [7 8 9]]) |