async icon indicating copy to clipboard operation
async copied to clipboard

Replace crossbeam-channel by flume

Open zazabe opened this issue 4 years ago • 11 comments

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

zazabe avatar Dec 31 '20 14:12 zazabe

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...

zazabe avatar Dec 31 '20 15:12 zazabe

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

vorner avatar Dec 31 '20 15:12 vorner

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.

zazabe avatar Dec 31 '20 15:12 zazabe

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.

vorner avatar Dec 31 '20 17:12 vorner

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

dpc avatar Jan 01 '21 05:01 dpc

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

vorner avatar Jan 03 '21 17:01 vorner

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

dpc avatar Jan 04 '21 20:01 dpc

Is this still a draft?

Techcable avatar Feb 10 '22 19:02 Techcable

Could be a config (feature) option.

dpc avatar Feb 10 '22 19:02 dpc

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: https://github.com/slog-rs/async/issues/21#issuecomment-762736542

njam avatar Feb 11 '22 16:02 njam

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

Techcable avatar Feb 11 '22 18:02 Techcable