Shell脚本实现求一个整数接近最近的2的次幂数的整数

RFS(Receive Flow Steering)扩展了 RPS 的性能以增加 CPU 缓存命中率,以此减少网络延迟。
RFS中的有个配置参数:/proc/sys/net/core/rps_sock_flow_entries
设置此文件至同时活跃连接数的最大预期值。对于中等服务器负载,推荐值为 32768 。所有输入的值四舍五入至最接近的2的幂。

当echo一个值设置到rps_sock_flow_entries时,会被设置为离这个值最近的2的次幂。由于一些需要,我需要用Shell实现这个类似的功能:给定一个正整数,计算出离它最近的2的次幂整数是多少。

写了个shell脚本:https://github.com/smilejay/shell/blob/master/sh2017/round_to_2_power_num.sh

运行效果:

RFS说明资料:
https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-networking-configuration_tools#sect-Red_Hat_Enterprise_Linux-Performance_Tuning_Guide-Configuration_tools-Configuring_Receive_Flow_Steering_RFS

master

Stay hungry, stay foolish.

发表评论

邮箱地址不会被公开。 必填项已用*标注

*