aiondemand / aiondemand/aiod-enhanced-interaction

Transform threads into tasks

Đang mở
#103 0 bình luận 0 reaction 1 người được giao Được @marcel-vesely-kinit nhận Xem trên GitHub
Ngôn ngữ chính
Python
Star
0
Fork
2
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

MongoDB beanie client doesn't seem to work well with multi-threaded application due to the way how ORM works and how it maps the actual Python classes to MongoDB collections. For now we have somewhat salvaged the main issue regarding this by enabling `multiprocessing_mode` for beanie, but it doesn't make the application thread-safe.

Ideally, in order for us to work with MongoDB application in a thread-safe manner, we would want to create a separate client within each thread, which we could and tried to do actually, but ORM logic overwrites the Python class definitions associated with document model that are shared between threads, which then leads to errors pertaining to event loops (simply put, the Python classes are always rewritten with the latest MongoDB client tied to the newly created thread/job, and then those Python classes are unusable for ORM purporses in other threads...)

We need to convert the following threads into tasks of the primary FastAPI thread:
- Embedding thread
- Search thread
- Setup job
- Recurring jobs (we need to change executor to create a task rather than a thread for recurring jobs)

Keep in mind that the initial reason for utilizing threads in the first place was the blocking nature of various AI inference computations which needs to be now explicitly separated into their own temporary threads in order not to block the execution of the main FastAPI thread. And obviously, we cannot put any code that interacts with MongoDB database into the auxiliary thread since that was the main reason why we need to convert these currently existing threads in the first place.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.