2015-04-30 45 views
1

我遇到一個冷到熱(首次使用)的集羣和會話到本地數據源(Cassandra)需要640ms。任何額外的連接需要80到100毫秒,所以第一個連接的開銷約爲500 + ms。這是正常的,有什麼我可以做些什麼來以某種方式得到這個數字?我使用T410(i5 2.5GHz)。Cassandra Java驅動冷至500毫秒熱?

[更新]

23:27:11.453 [main] DEBUG c.d.driver.core.SystemProperties - com.datastax.driver.NEW_NODE_DELAY_SECONDS is undefined, using default value 1 
23:27:11.460 [main] DEBUG c.d.driver.core.SystemProperties - com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE is undefined, using default value 4 
23:27:11.463 [main] DEBUG c.d.driver.core.SystemProperties - com.datastax.driver.NOTIF_LOCK_TIMEOUT_SECONDS is undefined, using default value 60 
23:27:11.607 [main] DEBUG com.datastax.driver.core.Cluster - Starting new cluster with contact points [localhost/127.0.0.1:9042] 
23:27:11.905 [main] DEBUG com.datastax.driver.core.Connection - Connection[localhost/127.0.0.1:9042-1, inFlight=0, closed=false] Transport initialized and ready 
23:27:11.906 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Refreshing node list and token map 
23:27:11.969 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Refreshing schema 
23:27:12.016 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Refreshing node list and token map 
23:27:12.051 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Successfully connected to localhost/127.0.0.1:9042 
23:27:12.052 [main] INFO c.d.d.c.p.DCAwareRoundRobinPolicy - Using data-center name 'datacenter1' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor) 
23:27:12.053 [main] INFO com.datastax.driver.core.Cluster - New Cassandra host localhost/127.0.0.1:9042 added 
23:27:12.076 [Cassandra Java Driver worker-0] DEBUG com.datastax.driver.core.Connection - Connection[localhost/127.0.0.1:9042-2, inFlight=0, closed=false] Transport initialized and ready 
23:27:12.077 [Cassandra Java Driver worker-0] DEBUG com.datastax.driver.core.Session - Added connection pool for localhost/127.0.0.1:9042 
23:27:12.097 [main] DEBUG com.datastax.driver.core.Connection - Connection[localhost/127.0.0.1:9042-2, inFlight=0, closed=true] closing connection 
23:27:12.103 [main] DEBUG com.datastax.driver.core.Cluster - Shutting down 
23:27:12.105 [main] DEBUG com.datastax.driver.core.Connection - Connection[localhost/127.0.0.1:9042-1, inFlight=0, closed=true] closing connection 
23:27:12.123 [main] DEBUG com.datastax.driver.core.Cluster - Starting new cluster with contact points [/127.0.0.1:9042] 
23:27:12.132 [main] DEBUG com.datastax.driver.core.Connection - Connection[/127.0.0.1:9042-1, inFlight=0, closed=false] Transport initialized and ready 
23:27:12.132 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Refreshing node list and token map 
23:27:12.138 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Refreshing schema 
23:27:12.168 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Refreshing node list and token map 
23:27:12.192 [main] DEBUG c.d.driver.core.ControlConnection - [Control connection] Successfully connected to /127.0.0.1:9042 
23:27:12.192 [main] INFO c.d.d.c.p.DCAwareRoundRobinPolicy - Using data-center name 'datacenter1' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor) 
23:27:12.192 [main] INFO com.datastax.driver.core.Cluster - New Cassandra host /127.0.0.1:9042 added 
23:27:12.201 [Cassandra Java Driver worker-0] DEBUG com.datastax.driver.core.Connection - Connection[/127.0.0.1:9042-2, inFlight=0, closed=false] Transport initialized and ready 
23:27:12.202 [Cassandra Java Driver worker-0] DEBUG com.datastax.driver.core.Session - Added connection pool for /127.0.0.1:9042 

正如人們所看到的第一個連接嘗試使用多達600毫秒,更取決於一個會如何讀的數字。

回答

3

我的猜測是這與連接初始化有關。在所有當前發佈的Java驅動程序版本中,連接都是同步初始化的。幸運的是,單個主機池並行初始化,但連接不是。如果您使用的是2.0.9,其默認的8個核心連接數可以解釋您爲什麼看到初始化時間較慢。另外,如果您使用密碼認證,那麼這會使系統的運行速度降低很多(從每個連接約0-10ms到約60-120ms)。

在即將發佈的java驅動程序2.0.10中,所有連接都是並行初始化的,這極大地改進了會話初始化。有關信息,請參閱JAVA-701

+0

我使用java驅動程序2.1.5和Cassandra 2.1.4。有沒有我可以調整的設置? –

+0

Hrm,可能是你可以做的事情。你連接了多少個cassandra節點?你在使用認證嗎?你有多少個CPU核心? (核心影響線程池的初始化連接的大小) –

+0

不壓縮不加密不驗證。它是一個用於測試目的的單個本地實例,每次運行一些測試時都會等待600毫秒,這是我希望減少的,因爲測試至少每兩分鐘運行一次。 –