有没有更快的方法来初始化BigQuery客户端?

时间:2019-03-19 12:48:31

标签: java google-bigquery vmware-fusion

使用建议的方法从Quickstart: Using Client Libraries处的google文档初始化BigQuery客户端需要15秒钟才能完成。这似乎很慢-有更快的方法吗?

import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryOptions;

public class Test {

  public static void main(String... args) throws Exception {

    long nanotime = System.nanoTime();
    BigQueryOptions x = BigQueryOptions.getDefaultInstance();
    System.out.println("getDefaultInstance " +
                                  (System.nanoTime()-nanotime));
    nanotime = System.nanoTime();
    BigQuery bigquery = x.getService();
    System.out.println("getService " + (System.nanoTime()-nanotime));
  }
}

输出:

getDefaultInstance 15453574055
getService 34049521
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 16.021s
Finished at: Tue Mar 19 14:23:54 GMT 2019
Final Memory: 7M/178M
------------------------------------------------------------------------

2 个答案:

答案 0 :(得分:2)

This is strange. I can run the same code on my end and it took less than 200ms to initialize. I'm running the code in a n1-standard-4 VM and using following versions for java:

openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

and 1.62 version for BigQuery client:

<dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-bigquery</artifactId>
      <version>1.62.0</version>
</dependency>

enter image description here

答案 1 :(得分:1)

问题某种程度上与虚拟机上的网络配置有关。将网络设置从“与Mac共享”更改为“桥接网络”已解决了该问题(请参见下图)。现在只需0.6秒即可初始化。

VMWare Network Adapter Settings