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

Mitigate write lock contention in reading CSV #66

Open
msk opened this issue Jul 21, 2020 · 0 comments
Open

Mitigate write lock contention in reading CSV #66

msk opened this issue Jul 21, 2020 · 0 comments
Labels
performance Performance improvement

Comments

@msk
Copy link
Collaborator

msk commented Jul 21, 2020

Reader::next_batch in reader.rs has the following:

let mut entry = map.entry(key.to_string()).or_insert_with(|| {
    self.enum_max_values.get(&i).map_or(
        (u32::max_value(), 0_usize),
        |v| {
            let mut value_locked = v.lock().expect("safe");
            if *value_locked < u32::max_value() {
                *value_locked += 1;
            }
            (*value_locked, 0_usize)
        },
    )
});

DashMap::entry tries to acquire a write lock on the underlying HashMap, waits until the lock becomes available. Since most of the time the routine above won't insert a new entry, attempting to get a write lock every time is a waste. Better to change it to a read lock for common cases.

@msk msk added the performance Performance improvement label Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance improvement
Projects
None yet
Development

No branches or pull requests

1 participant