Cloud Foundry Bind services/cups datasource number

2019-06-14 10:58发布

I am using hikari with spring boot, local testing I can see 50 active connections. After I deployed to cloud foundry , I am only able to see 10 active connections.

spring.datasource.hikari.maximum-pool-size=50

Seems like cloud foundry bind service is trying to overwrite my application's configuration. How can configure this number in cloud foundry?

maybe someone get help from this link, it says if you are running serious application in production , you need to configure DataSourceConfiguration

http://cloud.spring.io/spring-cloud-connectors/spring-cloud-spring-service-connector.html#_relational_database_db2_mysql_oracle_postgresql_sql_server

https://spring.io/blog/2015/04/27/binding-to-data-services-with-spring-boot-in-cloud-foundry

2条回答
Viruses.
2楼-- · 2019-06-14 11:58

I had to look up Hikari. According to this article it is a jdbc connection pool.

I am assuming then, you deployed Hikari as an app within Cloud Foundry and created a CUPS service from it. Is that correct?

You cannot modify the service thru the CUPS definition. It is only creating you an instance of that service.

Try setting the pool size either in the bootstrap.yml or by setting environment variables on the Hikari app to pass the default values. You may need to tweak the app to accept those variables at runtime.

If that doesn't work, you may have to create your own service broker, or generate a tile. That would give you options to manipulate the service.

Hope this helps!

查看更多
Ridiculous、
3楼-- · 2019-06-14 12:00

If you are including spring-boot-starter-cloud-connectors in your project, then the Spring Boot database properties aren't used. Spring Cloud Connectors will create and configure the Datasource bean automatically, unless you write the Java code to manually configure it.

As you found in the Connectors docs, you can write code like this to configure the connection properties, including pool size.

@Bean
public DataSource dataSource() {
    PoolConfig poolConfig = new PoolConfig(5, 30, 3000);
    DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, null);
    return connectionFactory().dataSource("database-service-name", dbConfig);
}

If you want to use Boot properties instead of writing code like this, you can remove spring-boot-starter-cloud-connectors from your project and configure the Boot properties using the vcap properties provided by Boot when apps are run on CF. Your maximum-pool-size property should be honored if you configure the connection in this way.

查看更多
登录 后发表回答