Giter Club home page Giter Club logo

Comments (7)

bdegomme avatar bdegomme commented on August 26, 2024 1

Hi @IAPark, would you consider adding a warning in the readme saying that the library is not thread safe? This leads to tricky deadlocks (I had the same as this one sidekiq/sidekiq#6084, took my 2-3 days to understand).
Unfortunately I don't think I could fix this myself 😬
Thank you for the great gem!

from tiktoken_ruby.

mkdynamic avatar mkdynamic commented on August 26, 2024 1

FWIW I think the fix is fairly simple, if the memoization is indeed the source of the thread safety issue.

Untested patch if it helps:
#30

from tiktoken_ruby.

IAPark avatar IAPark commented on August 26, 2024 1

This should now be fixed in the latest version

from tiktoken_ruby.

IAPark avatar IAPark commented on August 26, 2024

I'm not really sure how I would check for that. I think it should be? No unsafe rust features were used and I'm aware of anything wrong. Did you see something specific

from tiktoken_ruby.

mkdynamic avatar mkdynamic commented on August 26, 2024

I haven’t dug in deeply, but in a fairly heavily multi threaded app calling that method a lot results in some kind of deadlock for me (verified this with gdb, thread was stuck on that call).

My fix was to synchronize that call in a Mutex. And this solves the issue.

from tiktoken_ruby.

IAPark avatar IAPark commented on August 26, 2024

Interesting, this is a very low priority for me, but maybe I'll try digging into it one of these weekends

from tiktoken_ruby.

viamin avatar viamin commented on August 26, 2024

It looks like it's this usage of memoization inside a class method in lib/tiktoken_ruby/encoding.rb:

  def self.for_name_cached(encoding)
    @encodings ||= {}
    @encodings[encoding.to_sym] ||= Tiktoken::Encoding.for_name(encoding)
  end

Memoization inside a class method is not thread-safe. The easy fix might be to use a thread-safe memoization library like memo_wise

from tiktoken_ruby.

Related Issues (15)

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.