Slick 对 numThreads 和获得良好性能的最佳实践感到困惑 [英] Slick confused about numThreads and best practice for good performance

查看:19
本文介绍了Slick 对 numThreads 和获得良好性能的最佳实践感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 PlayFrameWork 与 Slick 一起使用,并在所有 I/O 数据库繁重的系统中使用它.在我的 application.conf 文件中,我有这个设置:

I am using the PlayFrameWork with Slick and using it in a system that is all I/O database heavy. In my application.conf file I have this setting:

play {
  akka {
    akka.loggers = ["akka.event.slf4j.Slf4jLogger"]
    loglevel = WARNING
    actor {
      default-dispatcher = {
        fork-join-executor {
          parallelism-factor = 20.0
        }
      }
    }
  }
}

这显然为播放应用程序的每个内核提供了 20 个线程,据我所知,Slick 创建了自己的线程池,Slick 中的 NumThreads 字段是指线程总数还是它(NumThreads x CPU's)?是否有最佳性能的最佳实践?我目前将我的设置配置为:

This obviously gives me 20 threads per core for the play application and as I understand it Slick creates it's own threadpool, is the NumThreads field in Slick mean that that's the total number of threads or is it (NumThreads x CPU's)? And is there any best practice for best performance? I currently have my settings configured as:

database {
  dataSourceClass = "org.postgresql.ds.PGSimpleDataSource"
  properties = {
    databaseName = "dbname"
    user = "postgres"
    password = "password"
  }
  numThreads = 10
}

推荐答案

numThreads 是线程池中的简单线程数.Slick 使用这个线程池来执行查询.

numThreads is simple number of thread in Thread pool. Slick use this thread pool for executing querying.

所有连接池都支持以下配置键,包括内置和第三方:

  • numThreads (Int, optional, default: 20):线程池中用于异步执行的并发线程数数据库操作.有关更多信息,请参阅 HikariCP wiki正确调整线程池的大小.注意对于异步在 Slick 中执行时,您应该调整线程池大小(这参数),而不是最大连接池大小.

  • numThreads (Int, optional, default: 20): The number of concurrent threads in the thread pool for asynchronous execution of database actions. See the HikariCP wiki for more imformation about sizing the thread pool correctly. Note that for asynchronous execution in Slick you should tune the thread pool size (this parameter) accordingly instead of the maximum connection pool size.

queueSize (Int, optional, default: 1000):数据库操作队列大小,不能立即执行线程很忙.超出此限制,新操作将立即失败.设置为 0 表示无队列(直接切换)或设置为 -1 表示无队列队列大小(不推荐).

queueSize (Int, optional, default: 1000): The size of the queue for database actions which cannot be executed immediately when all threads are busy. Beyond this limit new actions fail immediately. Set to 0 for no queue (direct hand-off) or to -1 for an unlimited queue size (not recommended).

默认情况下,池已针对异步执行进行了调整.在大多数情况下,除了连接参数外,您只需设置 numThreads 和 queueSize.在这种情况下,存在对线程池(通过其队列)而不是连接的争用,因此您可以对最大连接数设置相当大的限制(基于数据库服务器仍然可以处理的内容,而不是最多的高效的).在对事务中的非数据库操作进行排序时,Slick 将使用比池中线程更多的连接.

The pool is tuned for asynchronous execution by default. Apart from the connection parameters you should only have to set numThreads and queueSize in most cases. In this scenario there is contention over the thread pool (via its queue), not over the connections, so you can have a rather large limit on the maximum number of connections (based on what the database server can still handle, not what is most efficient). Slick will use more connections than there are threads in the pool when sequencing non-database actions inside a transaction.

HikariCP 支持以下配置键:

  • url(字符串,必填):JDBC URL

driver or driverClassName (String, optional): JDBC driver class to load user (String, optional)*: User name

driver or driverClassName (String, optional): JDBC driver class to load user (String, optional)*: User name

密码(字符串,可选):密码

isolation(字符串,可选):新连接的事务隔离级别.允许的值为:NONE、READ_COMMITTED、READ_UNCOMMITTED、REPEATABLE_READ、SERIALIZABLE.

isolation (String, optional): Transaction isolation level for new connections. Allowed values are: NONE, READ_COMMITTED, READ_UNCOMMITTED, REPEATABLE_READ, SERIALIZABLE.

目录(字符串,可选):新连接的默认目录.

readOnly(布尔值,可选):新连接的只读标志.

属性(Map,可选):要传递给驱动程序或数据源的属性.

properties (Map, optional): Properties to pass to the driver or DataSource.

dataSourceClass(字符串,可选):JDBC 驱动程序提供的 DataSource 类的名称.这优于使用司机.请注意,设置此键时将忽略 url(您必须使用属性来配置数据库连接).

dataSourceClass (String, optional): The name of the DataSource class provided by the JDBC driver. This is preferred over using driver. Note that url is ignored when this key is set (You have to use properties to configure the database connection instead).

ma​​xConnections(Int,可选,默认:numThreads * 5):池中的最大连接数.

minConnections(Int,可选,默认值:与 numThreads 相同):池中保留的最小连接数.

connectionTimeout(持续时间,可选,默认值:1s):在调用 getConnection 超时之前等待的最长时间.如果这超过时间而没有连接可用,一个将抛出 SQLException.1000ms 是最小值.

connectionTimeout (Duration, optional, default: 1s): The maximum time to wait before a call to getConnection is timed out. If this time is exceeded without a connection becoming available, a SQLException will be thrown. 1000ms is the minimum value.

validationTimeout(持续时间,可选,默认值:1s):测试连接活跃性的最长时间.1000ms是最小值.

validationTimeout (Duration, optional, default: 1s): The maximum amount of time that a connection will be tested for aliveness. 1000ms is the minimum value.

idleTimeout(持续时间,可选,默认值:10 分钟):允许连接在池中闲置的最长时间.值 0 表示空闲连接永远不会从水池.

idleTimeout (Duration, optional, default: 10min): The maximum amount of time that a connection is allowed to sit idle in the pool. A value of 0 means that idle connections are never removed from the pool.

maxLifetime(持续时间,可选,默认:30 分钟):最大值池中连接的生命周期.当空闲连接达到这个超时,即使最近使用过,也会从水池.值 0 表示没有最大生命周期.

maxLifetime (Duration, optional, default: 30min): The maximum lifetime of a connection in the pool. When an idle connection reaches this timeout, even if recently used, it will be retired from the pool. A value of 0 indicates no maximum lifetime.

connectionInitSql(字符串,可选):一条 SQL 语句,将在每次创建新连接后执行,然后将其添加到水池.如果此 SQL 无效或抛出异常,则会被视为连接失败,标准重试逻辑将是跟着.

connectionInitSql (String, optional): A SQL statement that will be executed after every new connection creation before adding it to the pool. If this SQL is not valid or throws an exception, it will be treated as a connection failure and the standard retry logic will be followed.

initializationFailFast(布尔值,可选,默认值:false):控制池是否会快速失败",如果池不能成功播种初始连接.如果连接不能在池启动时创建,将抛出 RuntimeException.如果 minConnections 为 0,则此属性无效.

initializationFailFast (Boolean, optional, default: false): Controls whether the pool will "fail fast" if the pool cannot be seeded with initial connections successfully. If connections cannot be created at pool startup time, a RuntimeException will be thrown. This property has no effect if minConnections is 0.

leakDetectionThreshold(持续时间,可选,默认值:0):在消息被发送之前,连接可以离开池的时间量记录表明可能的连接泄漏.值为 0 表示泄漏检测被禁用.允许泄漏的最低可接受值检测时间为10s.

leakDetectionThreshold (Duration, optional, default: 0): The amount of time that a connection can be out of the pool before a message is logged indicating a possible connection leak. A value of 0 means leak detection is disabled. Lowest acceptable value for enabling leak detection is 10s.

connectionTestQuery(字符串,可选):一个语句将在从连接获得之前执行池以验证与数据库的连接是否仍然有效.它依赖于数据库,应该是一个需要很少的查询由数据库处理(例如VALUES 1").未设置时,JDBC4使用 Connection.isValid() 方法代替(通常是最好).

connectionTestQuery (String, optional): A statement that will be executed just before a connection is obtained from the pool to validate that the connection to the database is still alive. It is database dependent and should be a query that takes very little processing by the database (e.g. "VALUES 1"). When not set, the JDBC4 Connection.isValid() method is used instead (which is usually preferable).

registerMbeans(布尔值,可选,默认值:false):是否注册了 JMX 管理 Bean(MBean").

registerMbeans (Boolean, optional, default: false): Whether or not JMX Management Beans ("MBeans") are registered.

Slick 有非常透明的配置设置.良好性能的最佳实践,没有拇指规则.这取决于您的数据库(提供多少并行连接)和您的应用程序.这完全是关于数据库和之间的调优.申请.

Slick have very transparent configuration setting.Best practice for good performance, There is no thumb rule. It depends on your database(how many parallel connection provides) and your application. It is all about tuning between database & application.

这篇关于Slick 对 numThreads 和获得良好性能的最佳实践感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆