如何使用 prisma 避免 java.util.concurrent.ThreadPoolExecutor 错误
Posted
技术标签:
【中文标题】如何使用 prisma 避免 java.util.concurrent.ThreadPoolExecutor 错误【英文标题】:how to avoid java.util.concurrent.ThreadPoolExecutor error with prisma 【发布时间】:2020-06-17 06:26:10 【问题描述】:我目前正在一个大型项目中使用 Prisma。执行复杂查询时,Prisma 集群经常在 docker-logs 中出错并显示以下消息(为了便于阅读,我正在编辑错误):
"key":"error/unhandled","requestId":"local:ck7ditux500570716cl5f8x3r","clientId":"default$default","payload":"exception":"java.util.concurrent.RejectedExecutionException: Task slick.basic.BasicBackend$DatabaseDef$$anon$3@552b85a4 rejected from slick.util.AsyncExecutor$$anon$1$$anon$2@1d4391f7[Running, pool size = 9, active threads = 9, queued tasks = 1000, completed tasks = 43440]","query":"query ($where: TaskWhereUniqueInput!)
\n task(where: $where) \n workflow \n tasks \n id\n state\n parentReq\n frozen\n parentTask \n id\n state\n \n \n \n \n\n","variables":
"\"where\":\"id\":\"ck6twx873bs550874ne867066\"",
"code":"0","stack_trace":"java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)\\n
java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
...
"message":"Task slick.basic.BasicBackend$DatabaseDef$$anon$3@552b85a4 rejected from slick.util.AsyncExecutor$$anon$1$$anon$2@1d4391f7[Running, pool size = 9, active threads = 9, queued tasks = 1000, completed tasks = 43440]"
这是处理大型查询时的常见错误。有没有人想出一种方法来配置 Prisma 或进行内部批处理操作以避免这种并发错误?
【问题讨论】:
【参考方案1】:选项 1:
我在循环中运行 prisma 突变时遇到了这个问题,其中包含大量似乎创建了太多并发数据库操作的数据。
我的解决方案是限制请求:
thingToLoop.map(() =>
await new Promise(resolve => setTimeout(resolve, 1000));
// Prisma operation here. Essentially this just makes the operation wait for one second between each operation.
)
选项 2
我读过其他帖子说您也可以设置并发连接数的限制。
见:https://v1.prisma.io/docs/1.25/prisma-server/database-connector-POSTGRES-jgfr/#overview
本质上,当创建的连接数过多时,这会限制连接数。以下面的 prisma 配置为例:
PRISMA_CONFIG: |
managementApiSecret: __YOUR_MANAGEMENT_API_SECRET__
port: 4466
databases:
default:
connector: postgres
migrations: __ENABLE_DB_MIGRATIONS__
host: __YOUR_DATABASE_HOST__
port: __YOUR_DATABASE_PORT__
user: __YOUR_DATABASE_USER__
password: __YOUR_DATABASE_PASSWORD__
connectionLimit: __YOUR_CONNECTION_LIMIT__
【讨论】:
以上是关于如何使用 prisma 避免 java.util.concurrent.ThreadPoolExecutor 错误的主要内容,如果未能解决你的问题,请参考以下文章
在java中,String转换Date日期类型容易出现时间转换异常,如何避免!
在java中,String转换Date日期类型容易出现时间转换异常,如何避免!