2015-04-03 31 views
8

我正在做一個涉及構建和查詢Cassandra數據集羣的學生項目。Cassandra超時cqlsh查詢大量(ish)數據量

當我的羣集負載很輕時(大約30GB),我的查詢運行沒有問題,但現在它有點大(1/2TB),我的查詢超時。

我認爲這個問題可能會出現,所以我纔開始生成和負載測試數據我已經在我的cassandra.yaml文件改變了這個值:

request_timeout_in_ms (默認值:10000)爲默認的超時其他,雜項操作。

但是,當我將該值更改爲1000000時,cassandra似乎在啓動時掛起 - 但這可能只是工作中的大暫停。

我的數據生成目標是2TB。如何查詢大量空間而不會超時?

查詢:

SELECT huntpilotdn 
FROM project.t1 
WHERE (currentroutingreason, orignodeid, origspan, 
     origvideocap_bandwidth, datetimeorigination) 
     > (1,1,1,1,1) 
AND  (currentroutingreason, orignodeid, origspan,  
     origvideocap_bandwidth, datetimeorigination) 
     < (1000,1000,1000,1000,1000) 
LIMIT 10000 
ALLOW FILTERING; 

SELECT destcause_location, destipaddr 
FROM project.t2 
WHERE datetimeorigination = 110 
AND  num >= 11612484378506 
AND  num <= 45880092667983 
LIMIT 10000; 


SELECT origdevicename, duration 
FROM project.t3 
WHERE destdevicename IN ('a','f', 'g') 
LIMIT 10000 
ALLOW FILTERING; 

我有同樣的模式演示密鑰空間,但遠小於數據大小(10GB〜),這些查詢運行在鍵空間就好了。

所有這些查詢表都有數百萬行和每行約30列。

+0

您可以發佈您的查詢的例子嗎? – Aaron 2015-04-03 19:10:15

回答

5

我猜你還在使用二級索引。您直接找到了不推薦二級索引查詢和ALLOW FILTERING查詢的原因......因爲這些類型的設計模式不能針對大型數據集進行擴展。用支持主鍵查詢的查詢表重建模型,這就是Cassandra設計的工作方式。

編輯

「受約束的變量是簇鍵」。

正確...這意味着它們不是分區鍵。在不限制分區密鑰的情況下,基本上可以掃描整個表,因爲集羣密鑰僅在分區密鑰內有效(羣集數據)。

+0

雖然我沒有使用二級索引。受約束的變量是「簇密鑰」。當我設置限制<5時,則查詢完成。對於如何使查詢在大於5的限制內完成,您還有什麼想法嗎? 編輯:我使用cqlsh來查詢我的數據庫你認爲我應該編寫一個應用程序來處理查詢嗎? – slmyers 2015-04-03 20:48:23

+3

@slmyers「受約束的變量是集羣密鑰。」正確...這意味着它們不是分區鍵。在不限制分區密鑰的情況下,基本上可以掃描整個表,因爲集羣密鑰只能將分區密鑰中的數據羣集在一起。 – Aaron 2015-04-03 23:29:53

6

要更改的Apache卡桑德拉客戶端超時限制,有兩種技術:

技術1:這是一個很好的技術:

1. Navigate to the following hidden directory under the home folder: (Create the hidden directory if not available) 

    $ pwd 
    ~/.cassandra 


2. Modify the file cqlshrc in it to an appropriate time in seconds: (Create the file if not available) 

    Original Setting: 

     $ more cqlshrc 
     [connection] 
     client_timeout = 10 
     # Can also be set to None to disable: 
     # client_timeout = None 
     $ 

    New Setting: 

     $ vi cqlshrc 
     $ more cqlshrc 
     [connection] 
     client_timeout = 3600 
     # Can also be set to None to disable: 
     # client_timeout = None 
     $ 

    Note: Here time is in seconds. Since, we wanted to increase the timeout to one hour. Hence, we have set it to 3600 seconds. 

技術2:這不是一個很好的技術,因爲你正在改變客戶端程序(cqlsh)本身的設置。 注意:如果您已經使用技術1進行了更改 - 那麼它將覆蓋使用技術2指定的時間。因爲配置文件設置具有最高優先級。

1. Navigate to the path where cqlsh program is located. This you can find using the which command: 

    $ which cqlsh 
    /opt/apache-cassandra-2.1.9/bin/cqlsh 
    $ pwd 
    /opt/apache-cassandra-2.1.9/bin 
    $ ls -lrt cqlsh 
    -rwxr-xr-x 1 abc abc 93002 Nov 5 12:54 cqlsh 


2. Open the program cqlsh and modify the time specified using the client_timeout variable. Note that time is specified in seconds. 
$ vi cqlsh 

In __init__ function: 
    def __init__(self, hostname, port, color=False, 
       username=None, password=None, encoding=None, stdin=None, tty=True, 
       completekey=DEFAULT_COMPLETEKEY, use_conn=None, 
       cqlver=DEFAULT_CQLVER, keyspace=None, 
       tracing_enabled=False, expand_enabled=False, 
       display_time_format=DEFAULT_TIME_FORMAT, 
       display_float_precision=DEFAULT_FLOAT_PRECISION, 
       max_trace_wait=DEFAULT_MAX_TRACE_WAIT, 
       ssl=False, 
       single_statement=None, 
       client_timeout=10, 
       connect_timeout=DEFAULT_CONNECT_TIMEOUT_SECONDS): 

In options.client_timeout setting: 
    options.client_timeout = option_with_default(configs.get, 'connection', 'client_timeout', '10') 

You can modify at both these places. The second line picks up client_timeout information from the cqlshrc file. 
25

如果您正在使用Datastax cqlsh那麼你就可以作爲命令行參數中指定的客戶端超時秒。缺省值是10

$ cqlsh --request-timeout=3600

Datastax Documentation