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

Improved output capturing and added tests #35

Merged
merged 7 commits into from
Jan 20, 2020

Conversation

ileasile
Copy link
Contributor

@ileasile ileasile commented Dec 18, 2019

Closes #32
Send output to client before the whole cell is calculated. May be triggered by:

  1. Exceeding buffer limit
  2. Newline symbol in output
  3. Some time after no flushing was performed

New and old functionality was covered with tests.
New config parameters were added

@ileasile ileasile requested a review from nikitinas December 18, 2019 16:45
@ileasile ileasile changed the title [#32] Improved output capturing and added tests #32 Improved output capturing and added tests Dec 18, 2019
@ileasile ileasile changed the title #32 Improved output capturing and added tests Improved output capturing and added tests closes #32 Dec 18, 2019
@ileasile ileasile changed the title Improved output capturing and added tests closes #32 Improved output capturing and added tests Dec 18, 2019

private fun shouldSend(b: Int): Boolean {
val c = b.toChar()
if (c == '\n' || c == '\r')
Copy link
Contributor

Choose a reason for hiding this comment

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

Use of line separator as a trigger for sending output can lead to excessive traffic. I suggest to add minimal buffer size to be sent on line separator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added additional option


override fun write(b: Int) {
if (++overallOutputSize > maxOutputSize) {
throw OutputLimitExceededException()
Copy link
Contributor

Choose a reason for hiding this comment

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

This exception will interrupt cell evaluation. This is not what user expects. If we want to limit output here, kernel should just stop sending it to frontend and continue cell execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

val resolverConfig: ResolverConfig?
val resolverConfig: ResolverConfig?,

val captureOutput: Boolean = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to put output capture parameters in kernel config as soon as we don't have an option to change it on kernel startup. Instead we may provide '%' line magic for user to change 'cellOutputMaxSize' and 'captureOutput'. For example,
%output [--no-stdout] [--no-stderr] [--max-size SIZE]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added output magic

@ileasile ileasile force-pushed the #32_improved_output_capturing branch 4 times, most recently from 7009970 to 8e7b96a Compare December 26, 2019 21:08
Copy link
Contributor

@nikitinas nikitinas left a comment

Choose a reason for hiding this comment

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

CapturingOutputStream is not working as expected. To implement correct behavior you need flush timer. And be careful with the first character of new line!

README.md Outdated
- `max-buffer-newline` - same as above, but trigger happens only if newline character was encountered. Default is 100.
- `max-time` - max time in milliseconds before the buffer is sent to client. Default is 100.
- `no-stdout` - don't capture output. Default is false.
- `reset-to-defaults` - reset all output settings that were set with magics to defaults
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems too specific to be placed in Readme file. We should add separate documentation file with such details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a separate file

if (captureOutput) capturedOutput.write(b)

if (captureOutput && overallOutputSize <= conf.cellOutputMaxSize) {
capturedOutput.write(b)
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes sending first character of next line together with previous line (if time since previous line output > timeLimit)

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, it was what I expected it test, and t seemed to me overcomplicated to make timer. But I think it's ok to make things good from the beginning, so i've implemented it.

capturedOutput.write(b)
if (shouldSend(b)) {
flush()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if no more output is produced, but the cell is still running? Who will flush the accumulated buffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added timer.

@ileasile ileasile force-pushed the #32_improved_output_capturing branch from bb03b9c to 1370ee2 Compare January 9, 2020 09:58
Copy link
Contributor

@nikitinas nikitinas left a comment

Choose a reason for hiding this comment

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

Good!

@nikitinas nikitinas merged commit d534c98 into master Jan 20, 2020
@nikitinas nikitinas deleted the #32_improved_output_capturing branch January 20, 2020 08:54
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.

println prints to console, but should print to output
2 participants