gpt4 book ai didi

ruby - 使用 Chef's Cookbook Recipe 动态覆盖属性

转载 作者:太空宇宙 更新时间:2023-11-03 17:54:11 28 4
gpt4 key购买 nike

我正在尝试为 Cassandra 设置一个新的 Recipe ,并在 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.

但是,无法确定属性中预定义的内核数磁盘驱动器数,因为部署的服务器可能具有不同的硬件设置。

是否可以使用部署的硬件设置动态覆盖属性?我读了Opscode doc而且我认为它没有办法捕获来自cat/proc/cpuinfo | grep 处理器 | wc -l

我在想这样的事情:

cookbook-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

cookbook-cassandra/attributes/default.rb

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

最佳答案

您可以使用 mixlib-shellout 在 Chef 中捕获 stdout(此处的文档:https://github.com/opscode/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

关于ruby - 使用 Chef's Cookbook Recipe 动态覆盖属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17608296/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com