mirror of https://github.com/langgenius/dify.git
perf: distribute concurrent plugin auto upgrade tasks (#26282)
This commit is contained in:
parent
0e4f19eee0
commit
043ec46c33
|
|
@ -1,3 +1,4 @@
|
||||||
|
import math
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
@ -8,6 +9,7 @@ from models.account import TenantPluginAutoUpgradeStrategy
|
||||||
from tasks.process_tenant_plugin_autoupgrade_check_task import process_tenant_plugin_autoupgrade_check_task
|
from tasks.process_tenant_plugin_autoupgrade_check_task import process_tenant_plugin_autoupgrade_check_task
|
||||||
|
|
||||||
AUTO_UPGRADE_MINIMAL_CHECKING_INTERVAL = 15 * 60 # 15 minutes
|
AUTO_UPGRADE_MINIMAL_CHECKING_INTERVAL = 15 * 60 # 15 minutes
|
||||||
|
MAX_CONCURRENT_CHECK_TASKS = 20
|
||||||
|
|
||||||
|
|
||||||
@app.celery.task(queue="plugin")
|
@app.celery.task(queue="plugin")
|
||||||
|
|
@ -30,15 +32,28 @@ def check_upgradable_plugin_task():
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
for strategy in strategies:
|
total_strategies = len(strategies)
|
||||||
process_tenant_plugin_autoupgrade_check_task.delay(
|
click.echo(click.style(f"Total strategies: {total_strategies}", fg="green"))
|
||||||
strategy.tenant_id,
|
|
||||||
strategy.strategy_setting,
|
batch_chunk_count = math.ceil(
|
||||||
strategy.upgrade_time_of_day,
|
total_strategies / MAX_CONCURRENT_CHECK_TASKS
|
||||||
strategy.upgrade_mode,
|
) # make sure all strategies are checked in this interval
|
||||||
strategy.exclude_plugins,
|
batch_interval_time = (AUTO_UPGRADE_MINIMAL_CHECKING_INTERVAL / batch_chunk_count) if batch_chunk_count > 0 else 0
|
||||||
strategy.include_plugins,
|
|
||||||
)
|
for i in range(0, total_strategies, MAX_CONCURRENT_CHECK_TASKS):
|
||||||
|
batch_strategies = strategies[i : i + MAX_CONCURRENT_CHECK_TASKS]
|
||||||
|
for strategy in batch_strategies:
|
||||||
|
process_tenant_plugin_autoupgrade_check_task.delay(
|
||||||
|
strategy.tenant_id,
|
||||||
|
strategy.strategy_setting,
|
||||||
|
strategy.upgrade_time_of_day,
|
||||||
|
strategy.upgrade_mode,
|
||||||
|
strategy.exclude_plugins,
|
||||||
|
strategy.include_plugins,
|
||||||
|
)
|
||||||
|
|
||||||
|
if batch_interval_time > 0.0001: # if lower than 1ms, skip
|
||||||
|
time.sleep(batch_interval_time)
|
||||||
|
|
||||||
end_at = time.perf_counter()
|
end_at = time.perf_counter()
|
||||||
click.echo(
|
click.echo(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue