-
Notifications
You must be signed in to change notification settings - Fork 78
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
Refactor logging into a separate thread (fix + enhancements) #642
Conversation
Update: checklist is done! All
Not sure what's best for this but I'm leaning more towards just moving away from the I also mentioned
After visiting this again, I don't really think there's a good reason for this. My initial idea was just to make the tests a bit easier but there is only one test that would benefit from this and the "boilerplate" is just 2 lines anyway. Lastly, I seem to not be getting any colors in my terminal for normal/accessible mode in neither my fork nor v0.5.1, am I supposed to? 😅 |
Not on Windows 😛, does your terminal support it? You could try changing this check and see what happens. Lines 18 to 19 in e992da2
Basically, I don't know what Windows terminals do parse ANSI codes properly, Regarding the PR, let me try something then I'll get back to you. |
Awesome work @AntoniosBarotsis ! |
I'll likely be busy until Sunday so I'll check the colour fix then. I get colors from stuff like cargo commands so they are supported, not sure if they work differently though |
Hey @AntoniosBarotsis is it OK for you if I make some edits on top of your branch changing how we set up the logging? |
Sure thing go ahead! Feel free to also discuss any potential issues you see with the implementation as is currently. |
and create another module inside of the logger module to reorganize things
use `std::sync::Barrier` instead of the barebones `Condvar` + `Mutex` combo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed your code commit by commit, approved. ✔️
Just let me know what you think we should do about that remaining warning log, Ideally I want to remove both those macros since they aren't really used anymore. I'll also take a look at everything myself again on Sunday. In the meantime, go ham with any nitpicks you have and I'll take a look if there's any. Was fun working on this! :) |
9544636
to
4d42ca3
Compare
Relatable, it was fun so I spent more time on this than I expected, I found some problems with warning output and STDIN synchronization, but I think I got it fixed now. @AntoniosBarotsis can you review my commits? (I recommend commit-by-commit instead of the whole diff) And maybe check benchmarks with the latest commit. |
I'll take a detailed look tomorrow and check the benchmarks again. Could you briefly explain what the stdin issue was? |
Yeah running the following code: ouch decompress archive.zip.gz Was not properly showing the warning. I also suspect that multiple STDIN questions could land simultaneously from different threads if decompressing in parallel. |
Ah I see, the issue was that I just forgot to log the warning when one was sent, works fine now indeed, nice catch.
So the way it worked before (with my changes) was that this piece of code would lock both stdout and stdin, the thinking being that other logs will be delayed (but not block any work since they would be collected by the logging thread (which now that I think of it, would cause some logs to disappear since I join 10 in a string and then clear so if stdout was already locked, some logs would arrive between receiving those 10 and actually logging them)) and then since you can ask for 1 input at a time, stdin would also be locked and block other threads that wanted to ask for user input since they can't do any work anyway. I don't think that anything is wrong with too many threads trying to lock stdin at the same time but we just need to make sure no logs are lost while everything is locked. Everything else looks fine to me but would be great to get another pair of eyes to review these. |
Ah yes just one thing I wanted to comment on was that maybe instead of sending a |
Rerun my benchmarks on the same zip archive from before:
I didn't run these enough times to average them out nicely but they seem to be slightly slower than before. After a bit more fiddling around, I found that most of the performance drop is in these lines that flush as removing those but keeping everything else as is brings this back to 13sec 423ms (+0.5s). Note that in my test I am using Edit: Not entirely sure if the question itself flushes (and so also prints the warning), but even if not, it would make more sense to add a flush there instead of where it is now. I haven't pushed any changes because I'm not sure if you have any local uncommitted changes from yesterday. |
Can you send me a new link to this piece of code, this one is not working. |
I dont know how I keep messing up these links 😅 Lines 7 and 9 from here (so the flushes). |
Hey, it's taking me even longer to respond cause I got a new job ( 😃😃🎉🎉 ).
This is the same as the other link, is there any chance you confused it and sent the wrong one? :v About the performance regression, I think that's OK if it's just for this corner case of
I don't have uncommitted changes, do you want to make any additional changes? If so, feel free to push them. |
Congrats!!! 😄
Ok I am convinced something weird is happening because the links point to my fork, when I click it I get this: In retrospect, honestly the performance gain is really not that noticeable from delaying the flush until actually necessary I think with that, I don't have anything else to add. |
I'm also getting the same, however, the two links point to the same location, while in the original message you talk about different results, so I assume both links should point to different locations.
hahahaha it happens! 😅 About the benchmarks, for I'll check what's pending in the unresolved conversations to finish and merge this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hartelijk dank!
Again, 😄.
WOOOO HOOOOOOOO |
Just want to remind that that potential deadlock bug was not fixed, what I wrote in the review was a suggestion! @marcospb19 I'll take a look at this again in a few weeks (and make an issue if its still there by then). I want to try and see if I can actually cause the bug and then fix it as well. |
See #632 for discussion. This PR does not implement the progress bar, just tackles the (performance) issues discussed in the PR related to logging.
Going to set this as a draft until the following checklist is complete just in case anyone wants to take a look while it's still being worked on.
Checklist
info
logswarning
logs *(done with one exception, see 4th point inThings to discuss
below)Things to check before merging
Note that I am currently getting 2 failing tests locally, these are failing because the log output is not updated yet (point 4 of the checklist), the messages are correct but
[INFO]
.Benchmarks
So far I've only tested decompression. I decided to compress the
ouch
repository for this (folder is around 2GB). I copied the contents of theouch
directory into aouch2
folder and zipped both that and the original totest1.zip
andtest2.zip
. The reason behind this is so when they get extracted in parallel, the filesystem trying to delete 1 copy and overwrite it with the other is not part of the benchmark (test1.zip -> ouch, test2.zip -> ouch2). Be sure to build ouch in release beforehand. I then ran the following:ouch d test1.zip test2.zip -y
orcargo r -- d test1.zip test2.zip -y
for both files and then for each file individually.Here's the results:
Of course it is worth pointing out that the performance gain is so big because there are a lot of files present in the archive and thus a lot of logs, the gain would be non-existent/negligible in cases where for instance one large file is being decompressed since there are not enough logs to speed up there.
Things to discuss
fixedwarning
logs currently ask foraccessible
even though it does not matterExplained in my next commentlog_sender
being needed in so many methods can get annoying (especially in testing), is it worth making it optional in some places?can macros be used to make any of this easier for the person trying to log thingsI think it is simple enough as is nowwarning
macro is not updated. This is because alog_sender
would be needed inside thisFromIterator
implementation. That obviously won't work however we could consider making a normal function for this instead of using the trait implementation. It seems that this is only really used here. Another idea would be to keep warnings outside of this logging thread system as there should not be that many warnings ever so performance would not really be a concern for them.