2013-07-12 150 views
1

我試圖建立對Cassandra的一個新的食譜,並在cassandra.yaml文件,其中有遵循有關最佳設置評論:用廚師的菜譜食譜動態覆蓋屬性

# For workloads with more data than can fit in memory, Cassandra's 
# bottleneck will be reads that need to fetch data from 
# disk. "concurrent_reads" should be set to (16 * number_of_drives) in 
# order to allow the operations to enqueue low enough in the stack 
# that the OS and drives can reorder them. 
# 
# On the other hand, since writes are almost never IO bound, the ideal 
# number of "concurrent_writes" is dependent on the number of cores in 
# your system; (8 * number_of_cores) is a good rule of thumb. 

然而,有沒有辦法確定屬性中預定義的numbers of coresnumbers of disk drives,因爲部署的服務器可能具有不同的硬件設置。

是否可以使用部署的硬件設置動態覆蓋屬性?我讀了Opscode doc,我不認爲它有一種方法來捕捉 cat /proc/cpuinfo | grep processor | wc -l

我在想是這樣的輸出:

食譜 - 卡桑德拉/食譜/ default.rb

cores = command "cat /proc/cpuinfo | grep processor | wc -l" 
node.default["cassandra"]["concurrent_reads"] = cores*8 
node.default["cassandra"]["concurrent_writes"] = cores*8 

食譜-卡桑德拉/屬性/ default.rb

default[:cassandra] = { 
    ... 
    # determined by 8 * number of cores 
    :concurrent_reads => 16, 
    :concurrent_writes => 16, 
    .. 
} 

回答

2

您可以通過mixlib-shellout(此處的文檔:https://github.com/opscode/mixlib-shellout)在主廚中捕獲stdout

在您的例子,你可以這樣做:

cc = Mixlib::ShellOut.new("cat /proc/cpuinfo | grep processor | wc -l") 
cores = cc.run_command.stdout.to_i # runs it, gets stdout, converts to integer 
2

我已經找到了一種方法食譜做到這一點,但我還沒有部署它沒有任何框以驗證它。

num_cores = Integer(`cat /proc/cpuinfo | grep processor | wc -l`) 
if (num_cores > 8 && num_cores != 0) # sanity check 
    node.default["cassandra"]["concurrent_reads"] = (8 * num_cores) 
    node.default["cassandra"]["concurrent_writes"] = (8 * num_cores) 
end 
0

我用的廚師11所以這可能並不適用於以前的版本,但有一個node['cpu']屬性與有關CPU的信息,內核等

chef > x = nodes.show 'nodename.domain'; true 
=> true 
chef > x['cpu']['total'] 
=> 16 

而且你可以用它你的食譜。這就是Nginx的食譜。