返回

postgresql——为什么HikariDataSource在谷歌云函数中实例化要花这么长时间?

发布时间:2022-07-22 11:48:29 317
# memcached

我有以下代码......

    val jdbcURL: String = String.format("jdbc:postgresql:///%s", dbName)
    val connProps = new Properties
    connProps.setProperty("user", dbUser)
    // Note: a non-empty string value for the password property must be set. While this property will be ignored when connecting with the Cloud SQL Connector using IAM auth, leaving it empty will cause driver-level validations to fail.
    if( dbUseIAM.equals("true") ){
      println("Using IAM password is ignored")
      connProps.setProperty("password", "ignored")
    } else {
      println("Using manual, password must be provided")
      connProps.setProperty("password", dbPassword)
    }
    connProps.setProperty("sslmode", ssoMode)
    connProps.setProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory")
    connProps.setProperty("cloudSqlInstance", instanceConnectionName)
    connProps.setProperty("enableIamAuth", dbUseIAM)
    // Initialize connection pool
    val config = new HikariConfig
    config.setJdbcUrl(jdbcURL)
    config.setDataSourceProperties(connProps)
    config.setMaximumPoolSize(1)
    config.setConnectionTimeout(15000) // 80% of 10s (Per Auth0 Action)
    config.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE") // TODO: Make configureable
    println("Config created")
    val pool : DataSource = new HikariDataSource(config) // Do we really need Hikari here if it doesn't need pooling?
    println("Returning the datasource")
    Some(pool)

它在本地调用并部署为云功能。在本地,脚本在不到 3 秒的时间内运行。但是,当我作为云功能部署到 GCP 时,我看到...

2022-07-19T20:10:36.833369Z
identity-corporatesru1oceg4a79 Config created
Info
2022-07-19T20:10:37.331144Z
identity-corporatesru1oceg4a79 Connecting to Cloud SQL instance [...:us-central1:db] via SSL socket.
Info
2022-07-19T20:10:37.331453Z
identity-corporatesru1oceg4a79 First Cloud SQL connection, generating RSA key pair.
Default
2022-07-19T20:10:52.434953Z
identity-corporatesru1oceg4a79 Returning the datasource 

请注意,返回数据源大约需要 5 秒。这里发生了什么,为什么云功能需要这么长时间?它在我的邮递员客户端上导致 504 超时。

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像