Internal server error on a lot of concurrent writing

prisma

#1

First I am not sure if this is prisma problem or database in general. So I am sorry guys I asked on wrong place.

So, here’s the case

Datamodel


type User {
  id: ID! @unique
  authorId: String! @unique
  name: String!
}

And here’s the code

const { prisma } = require("./generated/prisma-client");
const addUser = async () => {
  try {
    await prisma.upsertUser({
      where: {
        authorId: "a"
      },
      create: {
        authorId: "a",
        name: "a"
      },
      update: {
        name: "a"
      }
    });
  } catch (e) {
    console.error(e);
  }
};

Array(2030)
  .fill()
  .map(() => {
    addUser();
  });

It seems that I run addUser concurrently above 1008 times. I got error

{ Error: Whoops. Looks like an internal server error. Search your server logs for request ID: local:cjpvan0yi5cdd0a56uschgx5b ....

If I check docker logs, I can see this

{"key":"error/unhandled","requestId":"local:cjpv9x0100ffz0a56f3zotpy4","clientId":"default$default","payload":{"exception":"java.util.concurrent.RejectedExecutionException: Task slick.basic.BasicBackend$DatabaseDef$$anon$2@2a7bd0b rejected from slick.util.AsyncExecutor$$anon$2$$anon$1@64a38dbb[Running, pool size = 9, active threads = 9, queued tasks = 1000, completed tasks = 23718]","query":"mutation ($where: UserWhereUniqueInput!, $create: UserCreateInput!, $update: UserUpdateInput!) {\n  upsertUser(where: $where, create: $create, update: $update) {\n    id\n    authorId\n    name\n  }\n}\n","variables":"{\"where\":{\"authorId\":\"a\"},\"create\":{\"authorId\":\"a\",\"name\":\"a\"},\"update\":{\"name\":\"a\"}}","code":"0","stack_trace":"java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)\\n java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)\\n java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)\\n slick.util.AsyncExecutor$$anon$2$$anon$3.execute(AsyncExecutor.scala:161)\\n slick.basic.BasicBackend$DatabaseDef.runSynchronousDatabaseAction(BasicBackend.scala:264)\\n slick.basic.BasicBackend$DatabaseDef.runSynchronousDatabaseAction$(BasicBackend.scala:262)\\n slick.jdbc.JdbcBackend$DatabaseDef.runSynchronousDatabaseAction(JdbcBackend.scala:37)\\n slick.basic.BasicBackend$DatabaseDef.slick$basic$BasicBackend$DatabaseDef$$runInContextInline(BasicBackend.scala:241)\\n slick.basic.BasicBackend$DatabaseDef.runInContextSafe(BasicBackend.scala:147)\\n slick.basic.BasicBackend$DatabaseDef.run$1(BasicBackend.scala:176)\\n slick.basic.BasicBackend$DatabaseDef.slick$basic$BasicBackend$DatabaseDef$$runInContextInline(BasicBackend.scala:182)\\n slick.basic.BasicBackend$DatabaseDef.runInContextSafe(BasicBackend.scala:147)\\n slick.basic.BasicBackend$DatabaseDef.slick$basic$BasicBackend$DatabaseDef$$runInContextInline(BasicBackend.scala:206)\\n slick.basic.BasicBackend$DatabaseDef.runInContextSafe(BasicBackend.scala:147)\\n slick.basic.BasicBackend$DatabaseDef.runInContext(BasicBackend.scala:141)\\n slick.basic.BasicBackend$DatabaseDef.runInContext$(BasicBackend.scala:140)\\n slick.jdbc.JdbcBackend$DatabaseDef.runInContext(JdbcBackend.scala:37)\\n slick.basic.BasicBackend$DatabaseDef.runInternal(BasicBackend.scala:76)\\n slick.basic.BasicBackend$DatabaseDef.runInternal$(BasicBackend.scala:75)\\n slick.jdbc.JdbcBackend$DatabaseDef.runInternal(JdbcBackend.scala:37)\\n slick.basic.BasicBackend$DatabaseDef.run(BasicBackend.scala:73)\\n slick.basic.BasicBackend$DatabaseDef.run$(BasicBackend.scala:73)\\n slick.jdbc.JdbcBackend$DatabaseDef.run(JdbcBackend.scala:37)\\n com.prisma.api.connector.jdbc.impl.JdbcDatabaseMutactionExecutor.execute(JdbcDatabaseMutactionExecutor.scala:40)\\n com.prisma.api.connector.jdbc.impl.JdbcDatabaseMutactionExecutor.executeTransactionally(JdbcDatabaseMutactionExecutor.scala:26)\\n com.prisma.api.mutations.ClientMutationRunner$.$anonfun$run$2(ClientMutationRunner.scala:20)\\n scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:302)\\n scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)\\n scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)\\n akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)\\n akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)\\n scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)\\n scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)\\n akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)\\n akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)\\n akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)\\n akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)\\n akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)\\n akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)\\n akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)","message":"Task slick.basic.BasicBackend$DatabaseDef$$anon$2@2a7bd0b rejected from slick.util.AsyncExecutor$$anon$2$$anon$1@64a38dbb[Running, pool size = 9, active threads = 9, queued tasks = 1000, completed tasks = 23718]"}}

#2

Hi @Muhammad_Muhajir,

Can you please confirm that are you using the demo servers? If you using the demo servers those servers have some restrictions. Learn more about those restrictions here: https://www.prisma.io/docs/prisma-server/demo-servers-prisma-cloud-jfr3/#limitations

If you are not using demo servers and please tell more about your stack.


#3

Hi @pantharshit00,
Thanks again for the answer.

I am trying to do it locally on my laptop (with spec 2,7 GHz Intel Core i7 , 16 GB 2133 MHz LPDDR3 ) . Running on docker.

I have very limited understanding regarding database and scalability. Any assistance would be very helpful for me :slight_smile: .

And btw, it looks like the link you give requires login.


#4

Sorry I have updated the link. I have also answered your question on intercom.


#5

Hi @pantharshit00,

I’m having similar issues as @Muhammad_Muhajir does. I’m getting the same error message when trying to concurrently query more than 1000 entries from the database.

Could you please provide the answer you gave to @Muhammad_Muhajir within here?

My prisma server (v1.24) is connected to a MySQL database (v5.7). Both containers are running on the same VPS, I’m not using the demo servers.

Thank you!


#6

Similar issues here to. Any pointers - anyone?


#7

He was suggesting to use kubernetes. I haven’t done it yet thought.


#8

I think you are hitting the internal batch of 1000 items.

So you need to scale prisma temporary to import this data


#9

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.