# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
play.http.secret.key = "RItx1I:80?W@]8GAtPDuF8Ydd3mXM85p/<7og]Q;uBOdijQAauRDgu73B6`wQP59"

# The application languages
# ~~~~~
play.i18n.langs = [ "en" ]

# Disable default filters
play.filters.enabled = [ ]

play.modules {
  enabled += "startup.StartupModule"
}

play.server.server-header = "Play2"

play.server {
  netty {
    transport = "native"

    # Whether the Netty wire should be logged
    log.wire = false

    option {
      SO_BACKLOG = 8192
      SO_REUSEADDR = true
      "io.netty.channel.epoll.EpollChannelOption#SO_REUSEPORT" = true
      "io.netty.channel.epoll.EpollChannelOption#TCP_FASTOPEN" = 1

      child {
        SO_KEEPALIVE = true
        TCP_NODELAY = true
        SO_REUSEADDR = true

        # The default is 1 since Linux Kernel 3.13
        # You can check via "cat /proc/sys/net/ipv4/tcp_fastopen"
        # However 3 would be better, but we can't change it to that value because we don't have root permission when running the benchmarks
        "io.netty.channel.epoll.EpollChannelOption#TCP_FASTOPEN" = 1
      }
    }
  }
}

akka {
  actor {
    default-dispatcher {
      fork-join-executor {
        # one thread per core is enough
        # https://github.com/playframework/playframework/issues/7242#issuecomment-295215448
        parallelism-factor = 1.5

        # Information about the TechEmpower benchmark environment: https://www.techempower.com/benchmarks/#section=environment
        # The environment variable physical_cpu_count does NOT include the hyperthreaded cores!
        #parallelism-max = 14
        #parallelism-max = ${?thread_count}
        parallelism-max = 64

        task-peeking-mode="LIFO" # based on https://www.playframework.com/documentation/2.7.x/Migration24#Thread-pool-configuration
      }

      # https://doc.akka.io/docs/akka/2.5.11/dispatchers.html#looking-up-a-dispatcher
      # Throughput defines the maximum number of messages to be
      # processed per actor before the thread jumps to the next actor.
      # Set to 1 for as fair as possible.
      throughput = 64
    }
  }
}

# Number of database connections
# https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing
# db connections = ((physical_core_count * 2) + effective_spindle_count)
# https://www.techempower.com/benchmarks/#section=environment
fixedConnectionPool = 17
fixedConnectionPool = ${?db_pool_size}

database.dispatcher {
    executor = "thread-pool-executor"
    throughput = 1
    thread-pool-executor {
        fixed-pool-size = ${fixedConnectionPool}
    }
}

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
db {
    default {
        # https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
        url = "jdbc:mysql://tfb-database:3306/hello_world"
        username = "benchmarkdbuser"
        password = "benchmarkdbpass"
        hikaricp {
            dataSource {
                characterEncoding=UTF-8
                dontTrackOpenResources=true
                dontCheckOnDuplicateKeyUpdateInSQL=true
                cachePrepStmts=true
                prepStmtCacheSize=500
                prepStmtCacheSqlLimit=2048
                useServerPrepStmts=true
                useLocalSessionState=true
                useLocalTransactionState=true
                rewriteBatchedStatements=true
                cacheResultSetMetadata=true
                cacheServerConfiguration=true
                cacheCallableStmts=true
                callableStmtCacheSize=250
                elideSetAutoCommits=true
                maintainTimeStats=false
                alwaysSendSetIsolation=false
                zeroDateTimeBehavior="convertToNull"
                traceProtocol=false
                jdbcCompliantTruncation=false
                useUnbufferedInput=false
                useReadAheadInput=true
                useSSL=false
            }
            maximumPoolSize = ${fixedConnectionPool}
        }
    }
}

# Ebean configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
#
ebean.default = [ "models.*" ]
