Code Monkey home page Code Monkey logo

Comments (9)

gadelkareem avatar gadelkareem commented on July 16, 2024 1

Sure!

from limiter.

novln avatar novln commented on July 16, 2024

Hello,

Do you have any suggestions by any chances ?
Also, have you tried using redis store ? The in-memory store was more or less designed for debug and/or development.

Cheers,

from limiter.

novln avatar novln commented on July 16, 2024

Could I have an example of your expiration duration ?

from limiter.

gadelkareem avatar gadelkareem commented on July 16, 2024

Hello,

Do you have any suggestions by any chances ?
Also, have you tried using redis store ? The in-memory store was more or less designed for debug and/or development.

Cheers,

I think redis store would remove the the bottleneck since there is no cleaner on the app but for a single deployment it would create unneeded latency.
For the in-memroy the deletion of expired records could be done like this https://github.com/gadelkareem/cachita/blob/master/memory.go#L82 because of this issue golang/go#20135 but that would not be the best solution yet since cleaner will block again. I am not sure how to tackle the in-memory cleaner but maybe if there is a replica of the counters hash map that is used only for reading and the writing could be done through channels in go routines. But I am not sure how to do increment in this way.

Could I have an example of your expiration duration ?

generalLimiter = newLimiter("4-S")
apiLimiter = newLimiter("50-M")
searchLimiter = newLimiter("30-M")
func newLimiter(rate string) *limiter.Limiter {
    r, err := limiter.NewRateFromFormatted(rate)
    h.PanicOnError(err)
    return limiter.New(memory.NewStore(), r, limiter.WithTrustForwardHeader(true))
}

from limiter.

novln avatar novln commented on July 16, 2024

I may have a solution using a ring buffer, would you like to experiment it ?

from limiter.

novln avatar novln commented on July 16, 2024

@gadelkareem Could I have an example on how many keys you have in your store, so I could have a good telemetry on how my idea improve (or not) things ?!

Thank you.

from limiter.

gadelkareem avatar gadelkareem commented on July 16, 2024

@novln I am afraid that would be hard to calculate because it is production data but we can estimate it through the number of requests which is around 1.2 Million request per day.

from limiter.

novln avatar novln commented on July 16, 2024

Hello,

Could you try this commit 3cd0e5a?

I haven't done a benchmark nor a ring buffer in order to try to keep the initial architecture.
Also, it was quicker to try this and find a quick and good enough solution for your problem.

from limiter.

gadelkareem avatar gadelkareem commented on July 16, 2024

I tested it with stack impact and I do not see that blocker anymore but i made a PR so you can test it more intensely.

from limiter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.