Silly performance: making 12k mutex locks when I need one was really dumb.

This commit is contained in:
Herbert Wolverson
2024-03-12 14:20:35 -05:00
parent 5a3f90412d
commit e46aafe5ae
3 changed files with 5 additions and 9 deletions

View File

@@ -79,7 +79,7 @@ struct flow_data_t {
// This is pinned and not per-CPU, because half the data appears on either side of the bridge.
struct
{
__uint(type, BPF_MAP_TYPE_LRU_HASH); // TODO: BPF_MAP_TYPE_LRU_PERCPU_HASH?
__uint(type, BPF_MAP_TYPE_HASH); // TODO: BPF_MAP_TYPE_LRU_PERCPU_HASH?
__type(key, struct flow_key_t);
__type(value, struct flow_data_t);
__uint(max_entries, MAX_FLOWS);

View File

@@ -252,8 +252,7 @@ pub fn end_flows(flows: &mut [FlowbeeKey]) -> anyhow::Result<()> {
let mut map = BpfMap::<FlowbeeKey, FlowbeeData>::from_path("/sys/fs/bpf/flowbee")?;
for flow in flows {
let mut empty = FlowbeeData::default();
map.insert_or_update(flow, &mut empty)?;
map.delete(flow)?;
}
Ok(())

View File

@@ -182,6 +182,8 @@ impl ThroughputTracker {
// Track the expired keys
let mut expired_keys = Vec::new();
let mut lock = ALL_FLOWS.lock().unwrap();
// Track through all the flows
iterate_flows(&mut |key, data| {
@@ -193,7 +195,6 @@ impl ThroughputTracker {
// This flow has expired but not been handled yet. Add it to the list to be cleaned.
expired_keys.push(key.clone());
} else {
let mut lock = ALL_FLOWS.lock().unwrap();
// We have a valid flow, so it needs to be tracked
if let Some(this_flow) = lock.get_mut(&key) {
this_flow.0.last_seen = data.last_seen;
@@ -237,7 +238,6 @@ impl ThroughputTracker {
}); // End flow iterator
if !expired_keys.is_empty() {
let mut lock = ALL_FLOWS.lock().unwrap();
for key in expired_keys.iter() {
// Send it off to netperf for analysis if we are supporting doing so.
if let Some(d) = lock.get(&key) {
@@ -256,10 +256,7 @@ impl ThroughputTracker {
}
// Cleaning run
{
let mut lock = ALL_FLOWS.lock().unwrap();
lock.retain(|_k,v| v.0.last_seen >= expire);
}
lock.retain(|_k,v| v.0.last_seen >= expire);
}
}