Could use some help from Rust Twitter on this one: I want to provide each thread with a Vec in a thread-local. Then from another thread I want to periodically take ownership of the thread-local vecs and swap them with empty ones. Is there a good pattern/lib for this?
-
Show this thread
-
Replying to @yoshuawuyts
This almost seems like having a database (standalone or in-mem one) with thread local caching? Do you have an example of what kind of code would use that pattern?
1 reply 0 retweets 0 likes -
Replying to @bitshiftmask
haha, so this is for a logger. Actually believe
@sheevink suggested this. But the idea is to capture log messages into a thread-local bump allocator, and then every ~250ms we wake a driver thread that swaps the bump allocators and then logs the messages.2 replies 0 retweets 2 likes -
Replying to @yoshuawuyts @sheevink
Would it make sense to just have a thread local owned, heap allocated, vec, and when you're done filling it (size or time limited), then push the vec into a channel? Drain the channel from the log emitting thread?
2 replies 0 retweets 1 like -
Have a struct with an instant, a preallocated vec, and a channel producer. When size/timeout hits, swap the vec for a new one, shove it in the channel?
2 replies 0 retweets 1 like
yosh Retweeted yosh
Yeah I think that could work. There's one downside to this tho that may be tricky: https://twitter.com/yoshuawuyts/status/1264329331142262786 … Won't hit this on an active server (there's always a next message), but will hit it during local dev when there's little going on.
yosh added,
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.