天天看點

java.lang.RuntimeException:could not acquire a semaphore for execution

轉載自連結

近期測試在對整個系統進行壓力測試,發現并發數到30以上,去內建了oauth2的授權服務生成token時,便會出現大量報錯,在對授權服務的tomcat連結調整後,也無濟于事,于是單獨為授權服務進行壓力測試,發現在1000并發量上,連結正常無報錯,于是猜想可能是網關的問題,在百度搜尋後發現是網關配置的問題,以下就是搜尋到的結果,親測可行:

大緻可以看出是hystrix的問題,于是百度hystrix的相關配置,詳細配置: https://github.com/Netflix/Hystrix/wiki/Configuration

hystrix有兩種政策:

THREAD — 它在單獨的線程上執行,并發請求受線程池中線程數的限制

SEMAPHORE — 它在調用線程上執行,并發請求受信号量限制

看到其中:

于是配置檔案增加下面的配置:

hystrix.threadpool.default.coreSize=100

hystrix.threadpool.default.maxQueueSize=1500

hystrix.threadpool.default.queueSizeRejectionThreshold=1000

hystrix.command.default.execution.timeout.enabled=false

hystrix.command.default.execution.isolation.strategy=THREAD

問題解決。

繼續閱讀