Skip to content
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

Close video encoder pipes and wait for it to finalize the video before exiting #1503

Merged
merged 2 commits into from Aug 13, 2020

Conversation

Martchus
Copy link
Contributor

See https://progress.opensuse.org/issues/68923#note-9


I've tested it manually. So far I haven't noticed any truncated videos anymore. (Not when the test exists normally and also not when stopped by the worker.)

@codecov
Copy link

codecov bot commented Aug 10, 2020

Codecov Report

Merging #1503 into master will increase coverage by 0.08%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1503      +/-   ##
==========================================
+ Coverage   56.24%   56.32%   +0.08%     
==========================================
  Files          54       54              
  Lines        6353     6386      +33     
==========================================
+ Hits         3573     3597      +24     
- Misses       2780     2789       +9     
Impacted Files Coverage Δ
opt/backend/baseclass.pm 43.75% <0.00%> (+1.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3a8b48...ae542f1. Read the comment docs.

no autodie qw(close waitpid);
close $video_encoders->{$_}->{pipe} for keys %$video_encoders;
bmwqemu::diag 'Waiting for video encoder to finalize the video';
for (my $timeout = 30, my $interval = 1; $timeout > 0; sleep $interval, $timeout -= $interval) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the sleep mean we wait needlessly at least one second in every case? The for loop with a sleep isn't convincing me yet :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - it only sleeps when at least one video encoder process is still running. (Although it is not used often in Perl, this is a plain-old for loop and it behaves identical to the for loop in C/C++. The for loop has the advantage that all loop variables can be defined within the loop scope.)

By the way, I didn't simply make it two consecutive non-blocking waitpid calls because this way we couldn't implement a timeout. However, there's further cleanup code which is supposed to run so I'd refrain from blocking here forever.

Copy link
Contributor Author

@Martchus Martchus Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually ways to enforce a timeout more efficiently: https://stackoverflow.com/questions/282176/waitpid-equivalent-with-timeout https://codechacha.com/en/fork-waitpid-and-timeout
However, I think it isn't worth the effort (at this point). (Using sigtimedwait would likely be the best solution but it isn't directly available in Perl so I would have to write that part in C++.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I would prefer if you can show that the case of shutdown does not increase over what is actually necessary. Could you please provide some data from experiments to back this up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I've started a few tests which are very short and hence the video is also only ~2 minutes. Then the finalizing seems to be so fast that all the waiting code is basically a no-op, see the timestamps in the following logs:

�[0m�[37m[2020-08-11T13:55:40.423 CEST] [debug] isotovideo done
�[0m�[37m[2020-08-11T13:55:40.423 CEST] [debug] QEMU status is not 'shutdown', it is 'running'
�[0m�[37m[2020-08-11T13:55:40.423 CEST] [debug] BACKEND SHUTDOWN 
�[0m�[33m[2020-08-11T13:55:40.424 CEST] [info] ::: OpenQA::Qemu::Proc::save_state: Saving QEMU state to qemu_state.json
�[0m�[37m[2020-08-11T13:55:42.468 CEST] [debug] flushing frames
�[0mframe=  248 fps=1.8 q=0.0 Lsize=     431kB time=00:00:10.29 bitrate= 343.4kbits/s speed=0.0734x    
video:429kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.504507%
�[37m[2020-08-11T13:55:47.411 CEST] [debug] Waiting for video encoder to finalize the video
�[0m�[37m[2020-08-11T13:55:47.412 CEST] [debug] The external video encoder (pid 19794) terminated
�[0m�[37m[2020-08-11T13:55:47.412 CEST] [debug] The built-in video encoder (pid 19795) terminated
�[0m�[37m[2020-08-11T14:02:59.982 CEST] [debug] isotovideo done
�[0m�[37m[2020-08-11T14:02:59.983 CEST] [debug] QEMU status is not 'shutdown', it is 'running'
�[0m�[37m[2020-08-11T14:02:59.983 CEST] [debug] BACKEND SHUTDOWN 
�[0m�[33m[2020-08-11T14:02:59.984 CEST] [info] ::: OpenQA::Qemu::Proc::save_state: Saving QEMU state to qemu_state.json
�[0m�[37m[2020-08-11T14:03:02.024 CEST] [debug] flushing frames
�[0mframe=  250 fps=1.8 q=0.0 Lsize=     531kB time=00:00:10.37 bitrate= 419.3kbits/s speed=0.0741x    
video:529kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.413080%
�[37m[2020-08-11T14:03:05.479 CEST] [debug] Waiting for video encoder to finalize the video
�[0m�[37m[2020-08-11T14:03:05.479 CEST] [debug] The built-in video encoder (pid 21404) terminated
�[0m�[37m[2020-08-11T14:03:05.479 CEST] [debug] The external video encoder (pid 21403) terminated

Copy link
Member

@okurz okurz Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a shutdown time of 6-7s in the both cases you referenced which I consider bad. Do you know what caused it? I was now used to 1-2s after my last termination improvements. But the time between the later messages with just 1ms is negligible of course

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at the code again to find that out. It seems like my new code now duplicates the existing "flushing frames" handling for the internal video encoder. I somehow assumed we had no special handling for the old video encoder.

I better streamline the handling for the internal video encoder with the new code. I can also investigate why the "flushing frames" part takes so long.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now added the commit "Pass remaining frames to external video encoder as well". But it doesn't change the problem that it takes quite a while to send the remaining data to the internal video encoder.

@Martchus Martchus force-pushed the close-video-encoder-pipes branch 2 times, most recently from 2f4985e to 077fbb1 Compare August 12, 2020 15:23
backend/baseclass.pm Outdated Show resolved Hide resolved
backend/baseclass.pm Outdated Show resolved Hide resolved
This change unifies the existing code for "flushing frames" with the code
to stop the video encoder.

Now the remaining data is also passed to the external video encoder. The
error handling has also been improved and there's a timeout of 30 seconds
for the flushing.
Copy link
Member

@okurz okurz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov upload failed but coverage and test results look fine

@okurz okurz merged commit ffd3dd7 into os-autoinst:master Aug 13, 2020
@Martchus Martchus deleted the close-video-encoder-pipes branch August 14, 2020 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants