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

fix: limit concurrent HTTP requests #16

Merged
merged 3 commits into from
Jul 24, 2019

Conversation

lidel
Copy link
Member

@lidel lidel commented Jul 24, 2019

All HTTP requests made by this module are sent to the same delegate
host. Browsers throttle the number of concurrent requests per hostname.
Right now the limit is 6 per host, which suffocates connection pool to the delegate (#12)
blocking it from being used for preload in js-ipfs or delegated peer routing.

This PR:

  • introduces a task queue that limits the number of concurrent requests, making it safe to run in browser context
  • adds debug logs
  • changes default delegate

Additional optimizations:

Context: #12
Closes #12

All HTTP requests made by this module are sent to the same delegate
host. Browsers throttle the number of concurrent requests per hostname,
right now it is 6 per host, which suffocates the use of delegate and
blocking it from being used for preload or delegated peer routing.

This change introduces task queues that limit the number of concurrent
requests, making it safe to run in browser context.

Optimizations:
- preload calls via `refs` are known to take time,
  so we limit them to max two at a time
- swarm.connect was the main offender (causing multiple requests to delegate),
  we now check if connection is already present and cache result for 1 minute
  removing most of redundant http requests
- hostname of default delegate is changed

Context: libp2p#12
Closes libp2p#12

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
This removes all code that caused swarm connect calls from delegate to
self. It was not needed: delegate is one of bootstrap nodes,
so we are always connected to it.

libp2p#12 (comment)

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
We no longer need those (removed calls to swarm.connect)

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

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

This change looks good and should drastically cut down on requests

@jacobheun jacobheun merged commit 55d6108 into libp2p:master Jul 24, 2019
@jacobheun
Copy link
Contributor

Released in 0.3.1

@lidel lidel deleted the fix/http-throttling branch July 24, 2019 15:17
lidel added a commit to lidel/js-libp2p-delegated-content-routing that referenced this pull request Jul 26, 2019
This is a backport of the fix from
libp2p#16
that works with 0.2.x

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
jacobheun pushed a commit that referenced this pull request Jul 29, 2019
* fix: limit concurrent HTTP requests

This is a backport of the fix from
#16
that works with 0.2.x

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>

* refactor: simplify callbacks

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
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.

Request flood in web browser
2 participants