مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-12-01 05:43:04 +00:00
feat(worker): scale connection pool with worker threads
This will automatically increase the DB connection pool size if the number of threads needed in a worker is less than the maximum pool size configured.
هذا الالتزام موجود في:
@@ -60,6 +60,7 @@ module Worker
|
||||
def run
|
||||
logger.tagged(component: "worker") do
|
||||
setup_traps
|
||||
ensure_connection_pool_size_is_suitable
|
||||
start_work_threads
|
||||
start_tasks_thread
|
||||
wait_for_threads
|
||||
@@ -96,6 +97,23 @@ module Worker
|
||||
@exit_pipe_read.wait_readable(wait_time) ? true : false
|
||||
end
|
||||
|
||||
# Ensure that the connection pool is big enough for the number of threads
|
||||
# configured.
|
||||
#
|
||||
# @return [void]
|
||||
def ensure_connection_pool_size_is_suitable
|
||||
current_pool_size = ActiveRecord::Base.connection_pool.size
|
||||
desired_pool_size = @thread_count + 3
|
||||
|
||||
return if current_pool_size >= desired_pool_size
|
||||
|
||||
logger.warn "number of worker threads (#{@thread_count}) is more " \
|
||||
"than the db connection pool size (#{current_pool_size}+3), " \
|
||||
"increasing connection pool size to #{desired_pool_size}"
|
||||
|
||||
Postal.change_database_connection_pool_size(desired_pool_size)
|
||||
end
|
||||
|
||||
# Wait for all threads to complete
|
||||
#
|
||||
# @return [void]
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم