-
Notifications
You must be signed in to change notification settings - Fork 0
Thread Safety
Asimov::Client
should NOT be considered thread-safe.
That is, do not share instances of Asimov::Client
between different threads. While there's nothing explicitly non-thread safe in the Asimov::Client
at this time, this recommendation is being made to preserve the option to introduce implementations that are not thread-safe going forward.
There are essentially two options for using Asimov::Client
in a multi-threaded (or multi-fibered) context. These are:
- Create an
Asimov::Client
per thread/fiber - Use a thread-safe pool to manage your
Asimov::Client
instances
Instances are very cheap to create, so option 1 can be used without any significant impact on application performance.
If you wish to throttle the number of concurrent connections to OpenAI, or you wish to limit the number of Asimov::Client
instances for any other reason, there are excellent gems for pooling. We recommend connection_pool as a good option.
Generally speaking, Asimov should be configured at application startup, and the application-wide configuration should be treated as immutable thereafter. Changing the configuration after one has started creating Asimov::Client
instances may lead to inconsistent behavior.