Skip to content

Commit

Permalink
print subscription info; once per minute
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Apr 28, 2022
1 parent c715492 commit 366176a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 16 additions & 0 deletions core/src/server/rpc_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// DEALINGS IN THE SOFTWARE.

use std::collections::hash_map::Entry;
use std::collections::BTreeMap;
use std::fmt::{self, Debug};
use std::future::Future;
use std::ops::{Deref, DerefMut};
Expand Down Expand Up @@ -703,6 +704,21 @@ impl<Context: Send + Sync + 'static> RpcModule<Context> {
);
}

let subscribers2 = subscribers.clone();
std::thread::spawn(move || loop {
let mut conns = BTreeMap::new();

for (key, _) in subscribers2.lock().iter() {
conns.entry(key.conn_id).and_modify(|c| *c += 1).or_insert(1);
}

let mut v: Vec<_> = conns.into_iter().collect();
v.sort_by(|&(_, a), &(_, b)| b.cmp(&a));

tracing::info!("active subscription `{}`: {:?}", subscribe_method_name, v);
std::thread::sleep(std::time::Duration::from_secs(60))
});

// Unsubscribe
{
self.methods.mut_callbacks().insert(
Expand Down
7 changes: 6 additions & 1 deletion ws-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ impl<M: Middleware> Server<M> {
},
)));

tracing::info!("Accepting new connection, {}/{}", connections.count(), self.cfg.max_connections);
tracing::info!(
"Accepting new connection={}, {}/{}",
id,
connections.count(),
self.cfg.max_connections
);

id = id.wrapping_add(1);
}
Expand Down

0 comments on commit 366176a

Please sign in to comment.