perf: simulation acceleration - filter non-social entities + configurable semaphore

- Filter out non-social entity types (API, SDK, Database, etc.) from agent configs
  reduces agent count ~20%, fewer LLM calls per round
- Make semaphore configurable via SIMULATION_SEMAPHORE env var (default 50, up from 30)
  allows higher concurrent LLM requests for faster round execution
- Reddit semaphore also reads from env var
- Estimated speedup: ~2x (25min → ~12min for 40 rounds)
This commit is contained in:
liyizhouAI 2026-04-16 23:11:55 +08:00
parent b7df4880c8
commit d2b5b17b98
2 changed files with 23 additions and 4 deletions

View File

@ -293,7 +293,24 @@ class SimulationConfigGenerator:
)
reasoning_parts = []
# ========== 预过滤:排除非社交实体 ==========
NON_SOCIAL_ENTITY_TYPES = {
'API', 'SDK', 'Database', 'WebServer', 'CloudService', 'CloudProvider',
'Table', 'Module', 'ManagementBackend', 'SecurityMeasure', 'Condition',
'PaymentTime', 'RiskLevel', 'CurrentStatus', 'Order', 'OrderDetail',
'EnrollmentInfo', 'Software', 'Technology', 'ProcessManager', 'WebPage',
}
original_count = len(entities)
entities = [e for e in entities
if e.entity_type not in NON_SOCIAL_ENTITY_TYPES
and not any(kw in e.name for kw in ['GET /', 'POST /', 'PUT /', 'DELETE /', 'HTTPS API', 'JSAPI', 'INDEX(', 'Bearer token', 'Header', 'Hero'])]
filtered_count = original_count - len(entities)
if filtered_count > 0:
logger.info(f"过滤非社交实体: {original_count}{len(entities)} (排除 {filtered_count} 个技术/API实体)")
num_batches = math.ceil(len(entities) / self.AGENTS_PER_BATCH)
total_steps = 3 + num_batches
# ========== 步骤1: 生成时间配置 ==========
report_progress(1, t('progress.generatingTimeConfig'))
num_entities = len(entities)

View File

@ -1132,6 +1132,7 @@ async def run_twitter_simulation(
# Twitter 使用通用 LLM 配置
model = create_model(config, use_boost=False)
simulation_semaphore = int(os.environ.get("SIMULATION_SEMAPHORE", "50"))
# OASIS Twitter使用CSV格式
profile_path = os.path.join(simulation_dir, "twitter_profiles.csv")
@ -1160,7 +1161,7 @@ async def run_twitter_simulation(
agent_graph=result.agent_graph,
platform=oasis.DefaultPlatformType.TWITTER,
database_path=db_path,
semaphore=30, # 限制最大并发 LLM 请求数,防止 API 过载GLM RPM 友好值)
semaphore=simulation_semaphore, # 可通过 SIMULATION_SEMAPHORE 环境变量调整
)
await result.env.reset()
@ -1321,9 +1322,10 @@ async def run_reddit_simulation(
print(f"[Reddit] {msg}")
log_info("初始化...")
# Reddit 使用加速 LLM 配置(如果有的话,否则回退到通用配置)
model = create_model(config, use_boost=True)
reddit_semaphore = int(os.environ.get("SIMULATION_SEMAPHORE", "50"))
profile_path = os.path.join(simulation_dir, "reddit_profiles.json")
if not os.path.exists(profile_path):
@ -1351,7 +1353,7 @@ async def run_reddit_simulation(
agent_graph=result.agent_graph,
platform=oasis.DefaultPlatformType.REDDIT,
database_path=db_path,
semaphore=30, # 限制最大并发 LLM 请求数,防止 API 过载GLM RPM 友好值)
semaphore=reddit_semaphore, # 可通过 SIMULATION_SEMAPHORE 环境变量调整
)
await result.env.reset()