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 文档,但我认为它没有办法从 cat /proc/cpuinfo | grep processor | wc -l

我在想这样的事情:

食谱-cassandra/recipes/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

食谱-cassandra/属性/default.rb

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

3 回答 3

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
于 2013-07-13T00:34:34.350 回答
2

您可以使用(此处的文档:httpsstdout ://github.com/opscode/mixlib-shellout)在 Chef中捕获。mixlib-shellout

在您的示例中,您可以执行以下操作:

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
于 2013-07-12T19:21:50.887 回答
1

我使用的是 chef 11,所以这在以前的版本中可能不可用,但是有一个node['cpu']属性包含有关 cpus、核心等的信息。

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

你可以在你的食谱上使用它。这就是 Nginx 食谱的做法。

于 2014-11-07T17:31:58.860 回答