Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are db quesries asynchronous? #1034

Closed
Kesanov opened this issue Feb 22, 2018 · 3 comments
Closed

Are db quesries asynchronous? #1034

Kesanov opened this issue Feb 22, 2018 · 3 comments
Labels

Comments

@Kesanov
Copy link

Kesanov commented Feb 22, 2018

If I call ctx.run from multiple threads, will the database queries block each other ? For example:

class Main {
  import scala.concurrent.ExecutionContext.Implicits.global
  val ctx: Context = new PostgresJdbcContext[SnakeCase]( ... )

  def main(args: Array[String]): Unit = {
    // will a & b insert into database at the same time?
    val a = Future {ctx.run { .. insert into db .. }}
    val b = Future {ctx.run { .. insert into db .. }}
  }
}

What context should I use? PostgresJdbcContext or PostgresAsyncContext? Documentation does not really explain how do they differ and what is their purpose.

Is the maximum number of parallel queries equal to the size of connection pool?

What about the choice of ExecutionContext and usage of blocking { .. }.

@jilen
Copy link
Collaborator

jilen commented Feb 23, 2018

PostgresAsyncContext use nio-based driver
While PostgresJdbcContext just use the blocking jdbc driver.
You'd better first do some research with postgresql-async, and if you decide to use it, be careful about this bug

@Kesanov
Copy link
Author

Kesanov commented Feb 23, 2018 via email

@mosyp
Copy link
Collaborator

mosyp commented Feb 27, 2018

@Josef-Vonasek Yes, you can wrap scala execution context with fixed thread pool with number of threads equals to connection pool. The only restriction is to be careful with transactions since they need to be run in a single thread.
We have gitter channel for general-purpose questions https://gitter.im/getquill/quill

@mosyp mosyp closed this as completed Feb 27, 2018
@mosyp mosyp added the question label Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants