Skip to content

Commit

Permalink
[fix] prevent high qps from thrashing subscription channel
Browse files Browse the repository at this point in the history
  • Loading branch information
ealui-statsig committed May 24, 2024
1 parent 1388173 commit 725d617
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/servers/grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,9 @@ impl StatsigForwardProxy for StatsigForwardProxyServerImpl {

// Re-use broadcast channel if its already been created for
// a given sdk key
let contains_key = self
.update_broadcast_cache
.read()
.await
.contains_key(&sdk_key);
let mut rc = match contains_key {
true => self
.update_broadcast_cache
.read()
.await
let mut wlock = self.update_broadcast_cache.write().await;
let mut rc = match wlock.contains_key(&sdk_key) {
true => wlock
.get(&sdk_key)
.expect("We did a key check")
.sender
Expand All @@ -113,13 +106,11 @@ impl StatsigForwardProxy for StatsigForwardProxyServerImpl {
.add_observer(streaming_channel_trait)
.await;
let rv = sc.sender.read().await.subscribe();
self.update_broadcast_cache
.write()
.await
.insert(sdk_key.to_string(), sc);
wlock.insert(sdk_key.to_string(), sc);
rv
}
};
drop(wlock);

// After initial response, then start listening for updates
let ubc_ref = Arc::clone(&self.update_broadcast_cache);
Expand Down

0 comments on commit 725d617

Please sign in to comment.