使用Google Cloud Sql代理后响应时间增加

时间:2017-05-16 10:27:12

标签: hibernate kubernetes google-cloud-sql dropwizard google-kubernetes-engine

根据官方文档将我们的应用程序部署到Google Container引擎并通过Cloud Sql代理连接到Google Cloud Sql后,与通过Cloud Sql连接到Cloud Sql相比,api的响应时间增加了至少100 ms来自Google Compute Engine实例的ip白名单。

我写了一个简单的api,它在mysql上启动一个事务并使用hibernate提交它。以下是结果

+-----------------+--------------------+-----------------+-----------------+
| App Deployed on | Number of Requests | 99th percentile | Connecting Via  |
+-----------------+--------------------+-----------------+-----------------+
| GKE             |              20140 |           113ms | Cloud Sql Proxy |
| GCE             |              20895 |            13ms | IP whitelisting |
+-----------------+--------------------+-----------------+-----------------+

我的应用程序基于Dropwizard框架,我使用的是dropwizard-hibernate,下面是连接配置,对于GCE和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代码。

    @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);
        }
    }

0 个答案:

没有答案