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

Use semaphore isolation to limit concurrent requests #60

Closed
lance opened this issue Apr 30, 2017 · 5 comments
Closed

Use semaphore isolation to limit concurrent requests #60

lance opened this issue Apr 30, 2017 · 5 comments
Assignees

Comments

@lance
Copy link
Member

lance commented Apr 30, 2017

Fine Grained Bulkhead Pattern

The goal here is to implement a fine-grained bulkhead pattern similar to how Hystrix works in Java. This works hand-in-hand with circuit breakers to provide user-configurable client-side load balancing / throttling and helps to mitigate DoS attacks.

Before actually executing any of the circuit breaker wrapped code, the fire() function should acquire a semaphore, execute the function, and then release the semaphore. This prevents a client from unintentionally overloading a server with requests to a single resource, protecting against both programmer error (e.g. a loop that just spins, firing request after request), or malicious code designed to bring a service down.

Things to Consider

  • We need to find a reasonable default number of concurrent connections.
  • We need to decide if we should check the semaphore first, or if we should check the open state first. If the circuit is open, we are essentially throttling anyway, so we don't need to acquire a semaphore, and we're not using any additional external resources because we are failing fast.
  • Does this limit also affect the fallback functions? If we decide that we check open state first, and potentially fallback, should the fallback functions be subject to the same rate limiting behavior.
@lance
Copy link
Member Author

lance commented May 3, 2017

@lance lance self-assigned this May 9, 2017
@lance lance removed the ready label May 30, 2017
@lance lance assigned helio-frota and unassigned lholmquist Jun 2, 2017
@lance lance added the ready label Jun 2, 2017
@helio-frota
Copy link
Member

@lance I'm using https://www.npmjs.com/package/await-semaphore around the fire function.
Well, at least now I can run the tests and also this automatically runs the "leave".
But, I'm trying to understand to solve one issue with one of the tests (see on the screenshots ):

a
b

@helio-frota
Copy link
Member

I'm going to try again with semaphore.. this other library has some weird behavior I dunno.
When I change the capacity nothing happens, 0, 1, 100...

@lance
Copy link
Member Author

lance commented Jun 12, 2017 via email

@helio-frota
Copy link
Member

helio-frota added a commit that referenced this issue Jun 13, 2017
Also using blue-tape to fix a specific test and
Connects to #60
@lance lance closed this as completed in 8c0a46b Jun 20, 2017
@ghost ghost removed the in progress label Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants