-
Notifications
You must be signed in to change notification settings - Fork 48
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
multithreaded buse #11
base: master
Are you sure you want to change the base?
Conversation
its messy, but seems to work fine with the busexmp.c (not tested extensively, but no problems encountered on ext2 and btrfs) - it has no safeguards against creating excessive amount of threads. pretty sure it has over 10 threads running (for a split second) during mkfs.btrfs - but again, no problems encountered. fsck can't detect any problems on ext2, "btrfs check --repair" can't detect any errors on btrfs. - reading write requests from nbd is still single-threaded (but processing/writing them are multithreaded) - not sure how to fix that, i guess i'll need several sockets to nbd - writing responses to nbd is mutex locked (effectively single-threaded), again, not sure how to fix that, i guess i'll need several sockets to nbd i totally understand if you don't want to merge this, but i'd like an opinion of it either way ^^
I have concerns about your implementation. First it doesn't ensure that the replies are sent in the order the requests come in. You'll need to store the threads in a queue and handle the responses in order. Second are you sure that there are actually multiple requests coming in to NBD at once? What kinds of performance improvements did you see with multi- vs single-threading? |
thank you for taking a look! :)
|
Cool! You're right. Thanks for explaining. I'll have to play with that too. |
you asked about performance. note that i believe there's several things that can be improved on the multithreaded code, for instance, starting a new thread for every little minor request is probably crazy, having a thread pool would probably be faster, remember that actually creating a thread isn't free, threads should probably be resued, etc, anyway, i don't have anything interesting to test with at the moment, and i believe busexmp.c won't benefit much (if any) from multithreading, still: (warning: sorry, i do not have access to a completely quiet system to test on, there will be some noise. feel free to do your own tests ofc); creating a btrfs filesystem 100 times, single threaded buse.c running at /dev/ndb1 , and multithreaded busemt.c running at /dev/ndb0
bench.php:
(and if you wanna complain about how shitty PHP is, please do it elsewhere, like my email or /r/lolphp ) hdparm -Tt:
dd WRITE test:
dd READ test:
i guess i should test actual mounted filesystem performance too, suggestions? |
hmm, just occurred to me that the kernel's I/O caches may have screwed up my tests bigtime, i'm not sure. maybe try dd oflag=sync ? |
Nice work on the testing. Yes, you're right about the kernel's I/O caches. They can get pretty big. I've been working on some test programs to validate random accesses as well as filesystem level tests. Take a look and see if they're of use. They can also help validate your system to make sure what you write in is what is read back out. (For the record, the PHP thing didn't even cross my mind. Whatever gets the job done. You can always change it later if it's a problem.) |
I was thinking about this: what happens if there's a read on a sector followed by a write. Two threads are started, and the write thread is executed first, then the read. You may lose data if it doesn't handle the requests in sequence no? |
yeah that would be bad. however, i believe the kernel won't do that..? it would already be in memory, the kernel could probably get those bytes from there, from it's own I/O caches, and it'd be much faster. and you know how the kernel devs love to micro-optimize the shit out of everything? (except, ahm, /proc ), i asked this question on a linux support channel (##Linux @ freenode) , here's what i got (noise removed):
seems promising :) should probably ask on the Linux Kernel Mailing List too. (PS, I trust [R] , he's an ##linux oldtimer who's proven himself knowledgeable plenty times for years..) |
im just GUESSING, and, testing needs to be done to be sure. proc1 want to read sector 1-10 now, what if, all the time, there was a process 0 already writing to sector 1-8? i believe the kernel would have just issued a request to read sector 9-10 instead of 1-10 for proc1-2, and 11-15 for proc3 but if there's then a proc 4 wanting to write those sectors before the read requests have been finished? hmmmmmmmmmmmmmmmmmmmmmm idk. testing should definitely be done. |
is it possible the kernel would just have lied to the other programs and given them what proc 4 wanted to write, rather than what was actually on the BD? or would the kernel stall proc 4 write? idk. my guess goes to a stall of proc 4 write. should test. |
(but, if the kernel just issues the write request for proc 4 instantly, and don't want to lie to the other processes about what was actually on the BD at the time of the read request versus what is scheduled to be written, you're right, we have a problem. should test to be sure) |
All reads and writes (except for directio) go through the page cache. |
This looks like an interesting contribution, is it still in consideration? |
its messy, but seems to work fine with the busexmp.c (not tested extensively, but no problems encountered on ext2 and btrfs)
it has no safeguards against creating excessive amount of threads. pretty sure it has over 10 threads running (for a split second) during mkfs.btrfs - but again, no problems encountered. fsck can't detect any problems on ext2, "btrfs check --repair" can't detect any errors on btrfs.
reading write requests from nbd is still single-threaded (but processing/writing them are multithreaded) - not sure how to fix that, i guess i'll need several sockets to nbd
writing responses to nbd is mutex locked (effectively single-threaded), again, not sure how to fix that, i guess i'll need several sockets to nbd
i totally understand if you don't want to merge this, but i'd like an opinion of it either way ^^