FAQ
Hi,

We have released limiter (https://github.com/ulule/limiter) which is a rate
limit middleware
currently supporting in-memory or redis to store limits with a clean API.

Feedback welcome as always :)

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Matt Silverlock at Oct 6, 2015 at 12:22 am
    You should look at pipelining you Redis commands, specifically
    around https://github.com/ulule/limiter/blob/master/store_redis.go#L58-L82
    -

    Reasoning:

        - Best case is that you hit Redis twice (two network RTTs) per request
        if the key doesn't already exist
        - Worst case is that you have three RTTs for a key that already exists

    In the context of a HTTP server/where this package is acting as HTTP
    middleware that'll start to overtake the time spent blocking on other DB
    interactions.

    You should be able to improve this to 1x RTT for new keys and 2x RTT for
    existing keys without resorting to Lua, which could make it 1x RTT if you
    handle the "key exists => INCR => TTL" pathway in the script.

    https://gist.github.com/elithrar/22e414e067bbf6a5f2e6 (no promises that
    this will compile, but it should be very close if it doesn't)


    // Will return 0 (no-op) if the key already existsc.Send("SETNX", "key", 1)//
    Will return integer 0 if the key doesn’t existc.Send("EXPIRE", rate.Period.
    Seconds())c.Flush() exists, err := redis.Bool(c.Receive())if err != nil {
    return ctx, err} // We can ignore this: the value of exists tells us what
    we need.// (just need to flush the value out of the buffer)_, err := c.
    Receiveif err != nil { return ctx, err} if !exists { return Context{ // ...
    }} // In addition, for keys already existing, we need to INCR the value c.
    Send("INCR", key) c.Send("TTL", key) c.Flush() count, err := redis.Int64(c.
    Receive()) if err != nil { return ctx, err } ttl, err := redis.Int64(c.
    Receive()) if err != nil { return ctx, err } // Check count and TTL as per
    existing code // ... // ... return Context{ // ... }}



    Hope that's clear!


    On Tuesday, October 6, 2015 at 3:47:33 AM UTC+8, Florent Messa wrote:

    Hi,

    We have released limiter (https://github.com/ulule/limiter) which is a
    rate limit middleware
    currently supporting in-memory or redis to store limits with a clean API.

    Feedback welcome as always :)
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Florent Messa at Oct 6, 2015 at 8:42 pm
    Thank you for your comment.

    We have implemented
    transaction: https://github.com/ulule/limiter/commit/3c8a754d0f7d006ec0237bb791a3c44492860430
    On Tuesday, October 6, 2015 at 2:22:23 AM UTC+2, Matt Silverlock wrote:

    You should look at pipelining you Redis commands, specifically around
    https://github.com/ulule/limiter/blob/master/store_redis.go#L58-L82 -

    Reasoning:

    - Best case is that you hit Redis twice (two network RTTs) per request
    if the key doesn't already exist
    - Worst case is that you have three RTTs for a key that already exists

    In the context of a HTTP server/where this package is acting as HTTP
    middleware that'll start to overtake the time spent blocking on other DB
    interactions.

    You should be able to improve this to 1x RTT for new keys and 2x RTT for
    existing keys without resorting to Lua, which could make it 1x RTT if you
    handle the "key exists => INCR => TTL" pathway in the script.

    https://gist.github.com/elithrar/22e414e067bbf6a5f2e6 (no promises that
    this will compile, but it should be very close if it doesn't)


    // Will return 0 (no-op) if the key already existsc.Send("SETNX", "key", 1
    )// Will return integer 0 if the key doesn’t existc.Send("EXPIRE", rate.
    Period.Seconds())c.Flush() exists, err := redis.Bool(c.Receive())if err
    != nil { return ctx, err} // We can ignore this: the value of exists
    tells us what we need.// (just need to flush the value out of the buffer)_,
    err := c.Receiveif err != nil { return ctx, err} if !exists { return
    Context{ // ... }} // In addition, for keys already existing, we need to
    INCR the value c.Send("INCR", key) c.Send("TTL", key) c.Flush() count, err
    := redis.Int64(c.Receive()) if err != nil { return ctx, err } ttl, err :=
    redis.Int64(c.Receive()) if err != nil {
    ...
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dan Kortschak at Oct 6, 2015 at 8:55 pm
    A really minor comment. In the NewRateFromFormatted you define the syntax "reqs-period" using the dash. Why not make it read as what it means so people don't need to read docs to know immediately what is being done; change it to "reqs/period"?

    On 06/10/2015, at 6:17 AM, "Florent Messa" wrote:

    Hi,

    We have released limiter (https://github.com/ulule/limiter) which is a rate limit middleware
    currently supporting in-memory or redis to store limits with a clean API.

    Feedback welcome as always :)

    --
    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+unsubscribe@googlegroups.com .
    For more options, visit https://groups.google.com/d/optout.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 5, '15 at 7:47p
activeOct 6, '15 at 8:55p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase