Navigation Menu

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

Asynchronously stream requests to upstream when possible [feature] #251

Merged
merged 1 commit into from Jun 6, 2017

Conversation

AndrewDryga
Copy link
Member

Old implementation did buffering for any data that comes in and out of
the gateway, which produce several drawbacks:

  1. Memory usage was high
  2. Network I/O had many peaks (read full body and then send it to
    upstream)
  3. Higher latency (now upstream accepts connection almost instantly)
  4. It was impossible to send large files, because they consumed lots of
    memory on gateway side.

Current implementation will buffer only requests with application/json
content-type, allowing Logger to save them.

Future plans:

  • Find smarter way to log requests (by dropping secure data).
  • Use feature flags to async proxying JSON data.

stream_request_body(client_ref, upstream_request, conn)

{:error, reason} ->
{:error, reason} # TODO: return 502
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO found

def dispatch(%UpstreamRequest{} = upstream_request, %Conn{method: method} = conn) do
upstream_url = UpstreamRequest.to_upstream_url!(upstream_request)

# TODO: find better solution that dropping this for broken HTTPBin
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO found

stream_request_body(client_ref, upstream_request, conn)

{:error, reason} ->
{:error, reason} # TODO: return 502
Copy link
Member Author

Choose a reason for hiding this comment

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

Found a TODO tag in a comment: # TODO: return 502

def dispatch(%UpstreamRequest{} = upstream_request, %Conn{method: method} = conn) do
upstream_url = UpstreamRequest.to_upstream_url!(upstream_request)

# TODO: find better solution that dropping this for broken HTTPBin
Copy link
Member Author

Choose a reason for hiding this comment

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

Found a TODO tag in a comment: # TODO: find better solution that dropping this for broken HTTPBin


defp put_response_headers(conn, headers) do
headers
|> Enum.reduce(conn, fn
Copy link
Member Author

Choose a reason for hiding this comment

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

Use a function call when a pipeline is only one function long

@AndrewDryga
Copy link
Member Author

Ebert has finished reviewing this Pull Request and has found:

  • 5 possible new issues (including those that may have been commented here).
  • 4 fixed issues! 🎉

But beware that this branch is 4 commits behind the Nebo15:master branch, and a review of an up to date branch would produce more accurate results.

You can see more details about this review at https://ebertapp.io/github/Nebo15/annon.api/pulls/251.

Old implementation did buffering for any data that comes in and out of
the gateway, which produce several drawbacks:

1. Memory usage was high
2. Network I/O had many peaks (read full body and then send it to
upstream)
3. Higher latency (now upstream accepts connection almost instantly)
4. It was impossible to send large files, because they consumed lots of
memory on gateway side.

Current implementation will buffer only requests with application/json
content-type, allowing Logger to save them.

Future plans:
- Find smarter way to log requests (by dropping secure data).
- Use feature flags to async proxying JSON data.
@AndrewDryga AndrewDryga changed the title Asynchronously stream requests to upstream when possible Asynchronously stream requests to upstream when possible [feature] Jun 6, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 91.124% when pulling b279358 on async_requests into 754fda8 on master.

@AndrewDryga AndrewDryga merged commit 09220e4 into master Jun 6, 2017
@AndrewDryga AndrewDryga deleted the async_requests branch June 6, 2017 17:48
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