2 files changed, 23 insertions(+), 32 deletions(-)
M main.tcl
M ws.tcl
M main.tcl => main.tcl +23 -8
@@ 1,18 1,33 @@
#!/bin/env tclsh
package require logger
+package require json
-set msgs 0
-set start [clock seconds]
+set times [clock microseconds]
+set bufsize 10000
proc on_ws {sock mode data} {
- global start
- global msgs
- incr msgs
- set dur [expr {[clock seconds] - $start}]
- puts -nonewline "Recieved $msgs messages in $dur seconds. [expr {$msgs / ($dur+1)}] msgs/sec\r"
+ global times bufsize
+
+ set data [json::json2dict $data]
+
+ lappend times [dict get $data time_us]
+ set times [lrange $times end-[expr {$bufsize - 1}] end]
+
+ set start [lindex $times 0]
+ set end [lindex $times end]
+
+ set micros_per_N [expr {$end - $start}]
+ set secs_per_event [expr {$micros_per_N / [llength $times] / 1000000.0}]
+ set rate [expr {floor(1.0 / $secs_per_event)}]
+
+ if {[llength $times] < $bufsize} {
+ puts -nonewline "\33\[2K\rThe jetstream is producing $rate posts/sec ([llength $times] post sample)"
+ } else {
+ puts -nonewline "\33\[2K\rThe jetstream is producing $rate posts/sec"
+ }
flush stdout
}
-
source ws.tcl
::ws::c::connect jetstream2.us-east.bsky.network 443 /subscribe?wantedCollections=app.bsky.feed.post on_ws
vwait nil
+# &
M ws.tcl => ws.tcl +0 -24
@@ 244,27 244,3 @@ namespace eval ::ws::c {
}
}
}
-
-set msgs 0
-set start [clock seconds]
-proc on_ws {sock mode data} {
- global start
- global msgs
- incr msgs
- set dur [expr {[clock seconds] - $start}]
- puts -nonewline "Recieved $msgs messages in $dur seconds. [expr {$msgs / ($dur+1)}] msgs/sec\r"
- flush stdout
-
-# switch -- $mode {
-# 1 {
-# puts "Text frame from $sock: $data";
-# }
-# 2 {
-# puts "Binary frame from $sock."
-# }
-# }
-}
-
-::ws::c::connect jetstream2.us-east.bsky.network 443 /subscribe?wantedCollections=app.bsky.feed.post on_ws
-vwait nil
-