chi includes a middleware for this, see:
https://github.com/go-chi/chi/blob/master/middleware/throttle.go and some
examples here:
https://github.com/go-chi/chi/blob/master/_examples/limits/main.go

I haven't used it myself, but it seems to support having a fixed backlog as
well, which is important for backpressure, see:
https://www.somethingsimilar.com/2013/01/14/notes-on-distributed-systems-for-young-bloods/#backpressure

On Sat, Oct 28, 2017 at 6:23 AM, Keith Brown <keith6...@gmail.com> wrote:

> Here is a scenario: a high traffic site which executes costly operations
> (database / filesystem / compute heavy operations). The web server is
> running standard go/http/server.
>
> I would like to handle at most 100 requests and the remainder to queue --
> all while the client (curl) is waiting. Are there tools to throttle the web
> server? And is there a way to view the queue of work?
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jonathan Yu / *@jawnsy* on LinkedIn <https://linkedin.com/in/jawnsy>,
Twitter <https://twitter.com/jawnsy>, GitHub <https://github.com/jawnsy>,
Facebook <https://facebook.com/jawnsy>
*“Ever tried. Ever failed. No matter. Try again. Fail again. Fail better.”* —
Samuel Beckett, Worstward Ho (1983)

“In an adaptive environment, winning comes from adapting to change by
continuously experimenting and identifying new options more quickly and
economically than others. The classical strategist's mantra of sustainable
competitive advantage becomes one of serial temporary advantage.” — Navigating
the Dozens of Different Strategy Options
<https://hbr.org/2015/06/navigating-the-dozens-of-different-strategy-options>
 (HBR)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to