I am building a storage engine software that allows concurrent data writing, now I have two different choices here:
Method 1. Background Long-Running Thread
- Multiple user threads write to their own
WriteBuffer - A background long-running IO thread iterate all
write buffersand flush each write buffer one by one. (Need to obtain write buffer's mutex lock) - On each iteration, we can do a
this_thread::yield()to prevent block other jobs too long.
Method 2. Use User Threads
- Multiple user threads write to their own
WriteBuffer - On each user thread writes, we use this user thread to iterate all write buffers and flush buffers. (also need to obtain buffers mutex)
Can anyone tell which one is a better choice and why? Or do you have any other suggestions ? Thanks.