read-locks Turbine QUIC connection cache for lookups (#32687)
Frequently accessed remote addresses are cached, making a shared-lock sufficient which would reduce lock contention for the more common cache-hit lookups.
This commit is contained in:
parent
8c14886891
commit
349f5e0846
|
@ -294,8 +294,7 @@ async fn get_connection(
|
||||||
sender: Sender<(Pubkey, SocketAddr, Bytes)>,
|
sender: Sender<(Pubkey, SocketAddr, Bytes)>,
|
||||||
cache: Arc<RwLock<ConnectionCache>>,
|
cache: Arc<RwLock<ConnectionCache>>,
|
||||||
) -> Result<Connection, Error> {
|
) -> Result<Connection, Error> {
|
||||||
let key = (remote_address, /*remote_pubkey:*/ None);
|
let entry = get_cache_entry(remote_address, &cache).await;
|
||||||
let entry = cache.write().await.entry(key).or_default().clone();
|
|
||||||
{
|
{
|
||||||
let connection: Option<Connection> = entry.read().await.clone();
|
let connection: Option<Connection> = entry.read().await.clone();
|
||||||
if let Some(connection) = connection {
|
if let Some(connection) = connection {
|
||||||
|
@ -342,6 +341,17 @@ fn get_remote_pubkey(connection: &Connection) -> Result<Pubkey, Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_cache_entry(
|
||||||
|
remote_address: SocketAddr,
|
||||||
|
cache: &RwLock<ConnectionCache>,
|
||||||
|
) -> Arc<RwLock<Option<Connection>>> {
|
||||||
|
let key = (remote_address, /*remote_pubkey:*/ None);
|
||||||
|
if let Some(entry) = cache.read().await.get(&key) {
|
||||||
|
return entry.clone();
|
||||||
|
}
|
||||||
|
cache.write().await.entry(key).or_default().clone()
|
||||||
|
}
|
||||||
|
|
||||||
async fn cache_connection(
|
async fn cache_connection(
|
||||||
remote_address: SocketAddr,
|
remote_address: SocketAddr,
|
||||||
remote_pubkey: Pubkey,
|
remote_pubkey: Pubkey,
|
||||||
|
|
Loading…
Reference in New Issue