From 118a66cedc632097547210d6754258aa3f579e84 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Thu, 21 Nov 2024 19:30:28 -0500 Subject: [PATCH] well, until i exist on jetstream, ig this is where this project ends --- main.tcl | 31 +++++++++++++++++++++++-------- ws.tcl | 24 ------------------------ 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/main.tcl b/main.tcl index e249b33..c3a4f01 100755 --- a/main.tcl +++ b/main.tcl @@ -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 +# & diff --git a/ws.tcl b/ws.tcl index 3610cf4..8ff8da2 100644 --- a/ws.tcl +++ b/ws.tcl @@ -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 - -- 2.45.2