2015-07-20 101 views
-1

我無法通過Datastax PHP-和Java-Driver連接到我的3節點cassandra集羣。與Cassandra的連接速度很慢

特別是對於PHP驅動程序,至關重要的是我可以快速連接以改善我的網站加載時間。

我該如何調試?或者是什麼原因?

Java的輸出顯示這一點:

09:59:40,284 [main] DEBUG - com.datastax.driver.NEW_NODE_DELAY_SECONDS is undefined, using default value 1 
09:59:40,284 [main] DEBUG - com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE is undefined, using default value 4 
09:59:40,297 [main] DEBUG - com.datastax.driver.NOTIF_LOCK_TIMEOUT_SECONDS is undefined, using default value 60 
09:59:40,357 [main] DEBUG - Starting new cluster with contact points [/XXX.XXX.XXX.XXX:9042, /XXX.XXX.XXX.YYY:9042, /XXX.XXX.XXX.ZZZ:9042] 
09:59:40,402 [main] DEBUG - Using SLF4J as the default logging framework 
09:59:40,489 [main] DEBUG - java.nio.Buffer.address: available 
09:59:40,490 [main] DEBUG - sun.misc.Unsafe.theUnsafe: available 
09:59:40,490 [main] DEBUG - sun.misc.Unsafe.copyMemory: available 
09:59:40,490 [main] DEBUG - java.nio.Bits.unaligned: true 
09:59:40,492 [main] DEBUG - Java version: 8 
09:59:40,492 [main] DEBUG - -Dio.netty.noUnsafe: false 
09:59:40,492 [main] DEBUG - sun.misc.Unsafe: available 
09:59:40,492 [main] DEBUG - -Dio.netty.noJavassist: false 
09:59:40,665 [main] DEBUG - Javassist: available 
09:59:40,665 [main] DEBUG - -Dio.netty.tmpdir: /var/folders/4y/t4b47lbn1zjbjpb6x09l30wm0000gn/T (java.io.tmpdir) 
09:59:40,666 [main] DEBUG - -Dio.netty.bitMode: 64 (sun.arch.data.model) 
09:59:40,666 [main] DEBUG - -Dio.netty.noPreferDirect: false 
09:59:40,708 [main] DEBUG - com.datastax.driver.FORCE_NIO is undefined, using default value false 
09:59:40,710 [main] INFO - Did not find Netty's native epoll transport in the classpath, defaulting to NIO. 
09:59:40,714 [main] DEBUG - -Dio.netty.eventLoopThreads: 8 
09:59:40,723 [main] DEBUG - -Dio.netty.noKeySetOptimization: false 
09:59:40,723 [main] DEBUG - -Dio.netty.selectorAutoRebuildThreshold: 512 
09:59:40,747 [main] DEBUG - -Dio.netty.leakDetectionLevel: simple 
09:59:41,035 [main] DEBUG - com.datastax.driver.DISABLE_COALESCING is undefined, using default value false 
09:59:41,046 [main] DEBUG - Generated: io.netty.util.internal.__matchers__.com.datastax.driver.core.Message$ResponseMatcher 
09:59:41,066 [main] DEBUG - -Dio.netty.allocator.numHeapArenas: 4 
09:59:41,066 [main] DEBUG - -Dio.netty.allocator.numDirectArenas: 4 
09:59:41,066 [main] DEBUG - -Dio.netty.allocator.pageSize: 8192 
09:59:41,066 [main] DEBUG - -Dio.netty.allocator.maxOrder: 11 
09:59:41,067 [main] DEBUG - -Dio.netty.allocator.chunkSize: 16777216 
09:59:41,067 [main] DEBUG - -Dio.netty.allocator.tinyCacheSize: 512 
09:59:41,067 [main] DEBUG - -Dio.netty.allocator.smallCacheSize: 256 
09:59:41,067 [main] DEBUG - -Dio.netty.allocator.normalCacheSize: 64 
09:59:41,067 [main] DEBUG - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 
09:59:41,067 [main] DEBUG - -Dio.netty.allocator.cacheTrimInterval: 8192 
09:59:41,078 [main] DEBUG - Generated: io.netty.util.internal.__matchers__.com.datastax.driver.core.FrameMatcher 
09:59:41,082 [main] DEBUG - Generated: io.netty.util.internal.__matchers__.com.datastax.driver.core.Message$RequestMatcher 
09:59:41,104 [main] DEBUG - -Dio.netty.initialSeedUniquifier: 0x24d6f22f78c5a924 (took 8 ms) 
09:59:41,130 [main] DEBUG - -Dio.netty.allocator.type: unpooled 
09:59:41,130 [main] DEBUG - -Dio.netty.threadLocalDirectBufferSize: 65536 
09:59:41,197 [cluster1-nio-worker-0] DEBUG - Connection[/XXX.XXX.XXX.YYY:9042-1, inFlight=0, closed=false] Connection opened successfully 
09:59:41,218 [cluster1-nio-worker-0] DEBUG - -Dio.netty.recycler.maxCapacity.default: 262144 
09:59:41,432 [main] DEBUG - [Control connection] Refreshing node list and token map 
09:59:41,518 [main] DEBUG - [Control connection] Refreshing schema 
09:59:42,137 [main] DEBUG - [Control connection] Refreshing node list and token map 
09:59:42,315 [main] DEBUG - [Control connection] Successfully connected to /XXX.XXX.XXX.YYY:9042 
09:59:42,315 [main] INFO - Using data-center name '168' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor) 
09:59:42,315 [main] INFO - New Cassandra host /XXX.XXX.XXX.XXX:9042 added 
09:59:42,315 [main] INFO - New Cassandra host /XXX.XXX.XXX.YYY:9042 added 
09:59:42,315 [main] INFO - New Cassandra host /XXX.XXX.XXX.ZZZ:9042 added 
09:59:42,342 [cluster1-nio-worker-1] DEBUG - Connection[/XXX.XXX.XXX.XXX:9042-2, inFlight=0, closed=false] Connection opened successfully 
09:59:42,345 [cluster1-nio-worker-2] DEBUG - Connection[/XXX.XXX.XXX.YYY:9042-1, inFlight=0, closed=false] Connection opened successfully 
09:59:42,348 [cluster1-nio-worker-3] DEBUG - Connection[/XXX.XXX.XXX.ZZZ:9042-1, inFlight=0, closed=false] Connection opened successfully 
09:59:42,580 [cluster1-nio-worker-2] DEBUG - Added connection pool for /XXX.XXX.XXX.XXX:9042 
09:59:42,591 [cluster1-nio-worker-3] DEBUG - Added connection pool for /XXX.XXX.XXX.YYY:9042 
09:59:42,609 [cluster1-nio-worker-1] DEBUG - Added connection pool for /XXX.XXX.XXX.ZZZ:9042 

正如你所看到的,它需要約2.5秒,這是對我的使用情況太慢。

與PHP驅動程序相同,但我沒有這個日誌。

驅動程序連接後,查詢速度非常快。唯一的問題是連接時間太慢。我已將所有三個節點設置爲聯繫點。

編輯

只是爲了澄清:我的PHP驅動程序的問題。我想知道爲什麼它不使用池/持久連接。當我連續兩次調用腳本時,每次呼叫需要2-5秒。我認爲第二個電話應該是使用持續存儲池。 phpinfo()函數表示持久簇&會話= 0。這是我正在使用的代碼:

$cluster = Cassandra::cluster() 
     ->withContactPoints('XXX.XXX.XXX.XXX', 'XXX.XXX.XXX.YYY, 'XXX.XXX.XXX.ZZZ') 
     ->withCredentials('USERNAME', 'PASSWORD') 
     ->build(); 
$keyspace = 'myKeyspace'; 
$session = $cluster->connect($keyspace); 

UPDATE

問題是我的網絡。帶寬太少。

+0

請您在投票時告訴我我的問題有什麼問題。 – Stefan

回答

1

DataStax驅動程序是全功能驅動程序。他們知道你的custer拓撲和集羣狀態,這需要在集羣對象構建階段進行一些昂貴的操作。創建羣集對象需要多個秒(這取決於羣集的大小/節點數量)是很常見的。

最佳做法是不要爲每個請求創建羣集對象(這會非常低效)。相反,您希望一次構建羣集對象並保持連接處於打開狀態。然後,當您收到來自前端的請求時,請使用現有羣集對象進行處理。

正確使用時,卡桑德拉會給你非常快的響應時間。

對於其他c *客戶最佳實踐,請查看Brian's Cassandra Loader。這是一個很好的參考應用程序以及一個非常高效的散裝裝載機。

一些關鍵的最佳實踐包括:如果使用執行異步,如果使用批處理,請確保批處理是特定於標記以避免過度協調,請勿使用記錄的批處理,除非需要原子性,並且不要動態地從您的應用程序中操作您的模式以避免模式不匹配。

+0

嗨,這是非常真實的。但問題是,爲什麼每次當驅動程序應該堅持這些連接時,我的PHP實例都必須重新連接?剛剛更新了我的問題。 – Stefan