Skip to content

fix: allow for stdout and stderr streams to be unbufferred directly. - #708

Merged
sriram-mv merged 3 commits into
aws:developfrom
sriram-mv:python_unbufferred
Oct 16, 2018
Merged

fix: allow for stdout and stderr streams to be unbufferred directly.#708
sriram-mv merged 3 commits into
aws:developfrom
sriram-mv:python_unbufferred

Conversation

@sriram-mv

Copy link
Copy Markdown
Contributor

Issue #, if available:

  • N/A ( I can create one and reference it)

Description of changes:

  • Allow for stdout and stderr streams to be unbuffered by default.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sriram-mv
sriram-mv requested review from jfuss and sanathkr October 10, 2018 22:58

@sanathkr sanathkr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What are the performance impacts of making the streams unbuffered? How does this work/degrade in Windows cmd prompt and other non-iterm like terminals? How about through a SSH terminal?

I'd like us to be a bit thorough before enabling it globally.. I am okay if this is selectively added only when debugging because I know we might block the process for too long on sockets at that point..

Comment thread samcli/cli/main.py Outdated


@click.command(cls=BaseCommand)
@unbuffered_streams

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we do this selectively only for debugging?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For all of debugging? Can we scope this further down than that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we can scope it down to say "if you specify a debug port", I think its a fair trade off for performance.

@sriram-mv

sriram-mv commented Oct 11, 2018 via email

Copy link
Copy Markdown
Contributor Author
@sriram-mv

Copy link
Copy Markdown
Contributor Author

So I ran the integration tests with and without this commit on the local invoke path, and found no difference in timings.

Without this commit.

(aws_sam-sN63_SKq) srirammv@localrainbow:16:20:10:~/aws_sam_cli_WS/aws-sam-cli$time pytest tests/integration/local/invoke/
=============================================================================================================== test session starts ================================================================================================================
platform darwin -- Python 3.6.5, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /Users/srirammv/aws_sam_cli_WS/aws-sam-cli, inifile: pytest.ini
plugins: cov-2.4.0
collected 14 items

tests/integration/local/invoke/test_integrations_cli.py ............
tests/integration/local/invoke/runtimes/test_with_runtime_zips.py ..

============================================================================================================ 14 passed in 55.47 seconds ============================================================================================================

real	0m56.009s
user	0m12.071s
sys	0m2.177s

With commit

(aws_sam-sN63_SKq) srirammv@localrainbow:16:18:38:~/aws_sam_cli_WS/aws-sam-cli$time pytest tests/integration/local/invoke/
=============================================================================================================== test session starts ================================================================================================================
platform darwin -- Python 3.6.5, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /Users/srirammv/aws_sam_cli_WS/aws-sam-cli, inifile: pytest.ini
plugins: cov-2.4.0
collected 14 items

tests/integration/local/invoke/test_integrations_cli.py ............
tests/integration/local/invoke/runtimes/test_with_runtime_zips.py ..

============================================================================================================ 14 passed in 53.78 seconds ============================================================================================================

real	0m54.262s
user	0m11.396s
sys	0m2.190s

Also setting os.environ will only matter for that session of the invoke.

@sanathkr sanathkr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes more sense now. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually on second thought, can you skip the setting of "0" to facilitate usage of this class in multi-threaded scenarios. If you do

if self.debug_port:
  os.environ[...] = 1

then you don't have the race condition to worry about.

@sanathkr sanathkr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@sriram-mv
sriram-mv merged commit 34c7fb0 into aws:develop Oct 16, 2018
@sriram-mv sriram-mv mentioned this pull request Oct 19, 2018
heitorlessa added a commit to heitorlessa/aws-sam-cli that referenced this pull request Oct 30, 2018
* develop:
  chore: Version bump aws-sam-translator to 1.8.0 (aws#732)
  docs: add instructions for using local version of SAM Transformer (aws#688)
  docs: Update Docker command to docker (aws#725)
  fix: Iterate over query param list
  chore: Enable Travis to run integ tests
  chore(0.6.1): SAM CLI Version bump (aws#717)
  fix(init/readme): Correct permissions for AWS CLI under requirements (aws#713)
  add pytest-mock for testing (aws#703)
  fix: allow for stdout and stderr streams to be unbufferred directly. (aws#708)
  docs: Add installation instructions for linux (Centos) (aws#670)
  fix: Updated isBase64Encoded value to bool (aws#699)
  fix: correct launch.json for nodejs debugging through VSCode (aws#704)
  docs(usage): Update how to debug Python functions using VS Code (aws#694)
  docs(Cloud9): Reset bash cache on Cloud9 (aws#693)
  docs: Updated virtualenv alias name for 3.7 in guide. (aws#706)
  chore: update aws-sam-translator to 1.7.0 (aws#682)
  feat: travis CI support for Python 3.7 (aws#679)
  docs: Update generate-sample-event-payloads link (aws#702)
  Fix: Raise error for invalid environment variables file (aws#675)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants