After deploying our application on Google Container engine and connecting to Google Cloud Sql through Cloud Sql proxy as per official documentation ,api's response time has been increased by at-least 100 ms as compare to connecting to Cloud Sql via ip whitelisting from Google Compute Engine instance .
I have wrote a simple api which was starting a transaction on mysql and committing it using hibernate . Below are the results
+-----------------+--------------------+-----------------+-----------------+
| App Deployed on | Number of Requests | 99th percentile | Connecting Via |
+-----------------+--------------------+-----------------+-----------------+
| GKE | 20140 | 113ms | Cloud Sql Proxy |
| GCE | 20895 | 13ms | IP whitelisting |
+-----------------+--------------------+-----------------+-----------------+
My app is based on Dropwizard framework and I am using dropwizard-hibernate,below is connection configuration , which is same for both GCE and GKE :
database:
driverClass: com.mysql.jdbc.Driver
user: db_user
password: db_user_pass
url: jdbc:mysql://HOST_IP/db_name?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
maxWaitForConnection: 1s
validationQuery: "SELECT 1"
minSize: 8
maxSize: 42
properties:
charSet: UTF-8
hibernate.hbm2ddl.auto: validate
checkConnectionWhileIdle: false
maxConnectionAge : 10s
checkConnectionOnBorrow: true
Api code on which above experiment has been run .
@GET
@Path("/response/test")
@UnitOfWork
public LeaderBoardResp getLeaderBoardTest(){
long timeSpent = System.currentTimeMillis() - RequestThreadContext.get().getStartTimeMillis();
log.info(" Got a request on test api");
Stopwatch stopWatch = Stopwatch.createStarted();
try {
LeaderBoardResp leaderBoardResp = new LeaderBoardResp();
// fetchLeaderBoard.fetchLeaderBoard(leaderBoardReq);
return leaderBoardResp;
}finally {
stopWatch.stop();
log.info("total time in ms :: {} reqfilter time :: {} ",stopWatch.elapsed(TimeUnit.MILLISECONDS),timeSpent);
}
}