Giter VIP home page Giter VIP logo

Comments (7)

joshuap avatar joshuap commented on May 26, 2024

Thanks for the info, I'll look into this.

from honeybadger-ruby.

joshuap avatar joshuap commented on May 26, 2024

I wonder if using the Mutex class would solve the problem? http://www.ruby-doc.org/core-2.0.0/Mutex.html

from honeybadger-ruby.

nirvdrum avatar nirvdrum commented on May 26, 2024

A mutex on reads and writes would fix the issue, but that'd effectively only allow one request at a time. It wouldn't be terribly efficient.

from honeybadger-ruby.

joshuap avatar joshuap commented on May 26, 2024

Well, if this issue is only occurring when we duplicate the hash, I think we could get away with it there because it only happens every 60 seconds (when we send the metric data to the server). The duplication should happen relatively quickly, and the Mutex would prevent the race condition. Does that sounds right, or am I missing something?

from honeybadger-ruby.

joshuap avatar joshuap commented on May 26, 2024

This gem is also interesting, and looks similar to hamster: https://github.com/headius/thread_safe

from honeybadger-ruby.

nirvdrum avatar nirvdrum commented on May 26, 2024

The problem is you're reading while still writing to the hash. Putting a mutex around the read would just prevent two threads from reading at the same time . . . other threads would still be able to write. So you'd need to have the mutex around both the reads and the writes or come up with a ThreadLocal solution. Alternatively, you could push the dup from the read case to the write case, but you'd end up duping on every request. And without a mutex there, you could lose entries..

from honeybadger-ruby.

joshuap avatar joshuap commented on May 26, 2024

Cool, thanks for the help on this.

For posterity, it seems that the hamster gem provides thread safe constructs by making them immutable, however in our case we would still need to synchronize access to the metrics instance variable on every write. The thread_safe gem I mentioned above takes the second approach of wrapping every operation on the object in a mutex (or equivalent -- in JRuby, it uses the jruby/synchronized library, which appears to have been added to JRuby specifically for the thread_safe gem.

Since we're currently writing to the metrics hash in a single place and reading from it in a single place, I'm going to keep it simple and just add a lock in those two methods (Monitor#add_metric and Monitor#send_metrics). I'll revisit the need for an extra dependency or different approach once we further build out the metrics feature.

from honeybadger-ruby.

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.