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

Replace crossbeam-channel by flume #23

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zazabe
Copy link

@zazabe zazabe commented Dec 31, 2020

Replace crossbeam-channel by flume, which is coming with some advantages, see https://github.com/zesterer/flume#why-flume.

@zazabe zazabe changed the title Replace crossbeam-channel by flume Draft: Replace crossbeam-channel by flume Dec 31, 2020
@zazabe zazabe marked this pull request as draft December 31, 2020 14:36
@zazabe zazabe changed the title Draft: Replace crossbeam-channel by flume Replace crossbeam-channel by flume Dec 31, 2020
@zazabe
Copy link
Author

zazabe commented Dec 31, 2020

not sure if i'm right, but it seems flume::Sender/Reciever are not unwind-safe, because they are dependent on Spinlock, with no lock poisoning.

So it doesn't work well with slog::SendSyncUnwindSafeDrain trait...

@vorner
Copy link
Collaborator

vorner commented Dec 31, 2020

Aren't spin locks kind of a bad idea in general?

@zazabe
Copy link
Author

zazabe commented Dec 31, 2020

Not sure, maybe they have good reasons to use spinlocks ...

I created this PR because we found some performance issues with slog::async + crossbeam-channel.
For our use-case, with multiple log producers, channel send long-tail performance can be quite bad, so we decided to downgrade slog-async to 0.2.3 for now, which uses std::mpsc.
According to our benchmarks, flume doesn't have this perf degradation.

But it's probably more a crossbeam issue, i'll open a ticket there.

@vorner
Copy link
Collaborator

vorner commented Dec 31, 2020

Not sure, maybe they have good reasons to use spinlocks ...

They are generally quite fast because they are simple and they don't need OS support. But if the thread is ever preempted while the lock is held, other threads will burn CPU for the whole scheduler tick (and even yielding to the OS scheduler doesn't have to help, if enough of them are spinning, they will keep turns). So in a sense, they can be faster, but they also have much more severe „failure“ mode. That's why eg. parking_lot spins for few turns, but then suspends on a real OS-backed mutex.

I guess the problem with crossbeam is that it runs kind of GC thing from time to time, which takes time on one of the CPUs. But I'd be wary of putting a spinlock into logging for the above reason.

@dpc
Copy link
Contributor

dpc commented Jan 1, 2021

Well... I'm not sure what to do about it. :D

@vorner
Copy link
Collaborator

vorner commented Jan 3, 2021

OK, I've had a look at flume and it seems not to be using the spin lock as a mutex: zesterer/flume#29 (comment). So my fear of spin-locks here is probably not warranted.

@dpc
Copy link
Contributor

dpc commented Jan 4, 2021

So... all agree that flume is better? :D

@Techcable
Copy link
Member

Is this still a draft?

@dpc
Copy link
Contributor

dpc commented Feb 10, 2022

Could be a config (feature) option.

@njam
Copy link
Collaborator

njam commented Feb 11, 2022

Just to add that @zazabe and I eventually settled on using std::sync::mpsc and not flume because the performance was better with mpsc for our use case.

See some benchmark data here: #21 (comment)

@Techcable
Copy link
Member

Techcable commented Feb 11, 2022

Maybe we should put both flume and crossbeam behind feature flags, that way people can pick whatever they want.....

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.

5 participants