Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LRU in connection-cache #24109

Merged

Conversation

ryleung-solana
Copy link
Contributor

Problem

connection-cache currently uses a home-grown least-recently-used cache, which is not preferred, since there's an LRU package.

Summary of Changes

Switches connection-cache to use LRU

Fixes #

…ur home-grown least-recently-used cache works properly. Now that we've switched to using the LRU package, it's better to rely on the tests in the package itself
client/src/connection_cache.rs Show resolved Hide resolved
@@ -162,82 +125,3 @@ pub fn par_serialize_and_send_transaction_batch(
Connection::Quic(conn) => conn.par_serialize_and_send_transaction_batch(transactions),
}
}

#[cfg(test)]
mod tests {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we still need some tests even using lru

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, though I haven't been able to think of an appropriate test here, since before the tests basically tested whether our home-grown LRU cache did what it was supposed to. Now that we're using the LRU crate, it's more appropriate to rely on the crate's tests for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add some simple get calls make sure we are using that correctly.

t-nelson
t-nelson previously approved these changes Apr 5, 2022
Copy link
Contributor

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with the metrics moved out to a separate PR and Lijun's suggestion for a simple test ensuring LRU behavior


match map.map.get(addr) {
Some(connection) => {
inc_new_counter_info!("get_connection-cache-hits", 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's save the metrics for a separate PR

let (_, send_socket) = solana_net_utils::bind_in_range(
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
VALIDATOR_PORT_RANGE,
)
.unwrap();
let conn = if use_quic {
let connection = if map.use_quic {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to refrain from superfluous renames in logical change commits (in the future)

Connection::Quic(Arc::new(QuicTpuConnection::new(send_socket, *addr)))
} else {
Connection::Udp(Arc::new(UdpTpuConnection::new(send_socket, *addr)))
};

entry.insert((conn.clone(), ticks));
(conn, ticks)
map.map.put(addr.clone(), connection.clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
map.map.put(addr.clone(), connection.clone());
map.map.put(*addr, connection.clone());

SockAddr is Copy. Odd that clippy didn't complain 🤔

@mergify mergify bot dismissed t-nelson’s stale review April 5, 2022 22:50

Pull request has been modified.

Copy link
Contributor

@lijunwangs lijunwangs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@codecov
Copy link

codecov bot commented Apr 6, 2022

Codecov Report

Merging #24109 (fb441e9) into master (2da4e3e) will decrease coverage by 0.0%.
The diff coverage is 81.9%.

@@            Coverage Diff            @@
##           master   #24109     +/-   ##
=========================================
- Coverage    81.8%    81.7%   -0.1%     
=========================================
  Files         581      590      +9     
  Lines      158312   161002   +2690     
=========================================
+ Hits       129518   131558   +2040     
- Misses      28794    29444    +650     

@ryleung-solana ryleung-solana merged commit a38bd4a into solana-labs:master Apr 6, 2022
mergify bot pushed a commit that referenced this pull request Apr 13, 2022
Switch to using LRU for connection-cache

(cherry picked from commit a38bd4a)

# Conflicts:
#	gossip/src/cluster_info_metrics.rs
ryleung-solana added a commit that referenced this pull request Apr 13, 2022
Switch to using LRU for connection-cache
ryleung-solana added a commit that referenced this pull request Apr 14, 2022
Switch to using LRU for connection-cache

Co-authored-by: ryleung-solana <91908731+ryleung-solana@users.noreply.github.com>
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 28, 2022
Switch to using LRU for connection-cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants