我是一家电子商务公司的开发人员,我正在运行使用 ruby on rails spree commerce 构建的电子商务应用程序。我目前在生产中运行 2 个中型实例。一个是高内存实例,具有 3.8 RAM 和单核 CPU,另一个是高 CPU 实例,具有双核 CPU。基本上 AWS 分别称它为 m1.medium 和 c1.medium 实例。我的问题是,是否可以根据 CPU 密集度和内存密集度分离进程?这样,所有 CPU 密集度进程都可以在高 CPU 实例中运行,所有内存密集度进程都可以在高内存实例中运行。是否有任何工具可用于识别这些进程。请提醒我。谢谢
答案1
很少能正确地将这些任务分开,通常 CPU 密集型任务和内存密集型任务在同一个机器上可以完美共存。我猜大多数时候使用 AWS 的公司都会构建尽可能均匀的负载设备,因为您需要使用相对同质的硬件设备(少数特殊情况(数据库服务器))。我宁愿尝试找出哪个是最便宜的实例,您可以运行您的堆栈至少 2 次(但建议 3 次)。通过这种方式,您可以实现更高的可用性和更少的性能开销。您需要的工具是 Linux 上的 ps(以及其他一些操作系统)。
中央处理器:
ps -eo 'pcpu,%cpu,pid,comm' | grep -v '%CPU PID COMMAND' | sort -n
记忆:
ps -eo 'rss,%mem,pcpu,%cpu,pid,comm' | grep -v '%CPU PID COMMAND' | sort -n
请参阅手册页的字段部分以了解更多信息:
CODE HEADER DESCRIPTION
%cpu %CPU cpu utilization of the process in "##.#" format. Currently, it is the CPU time used divided by the
time the process has been running (cputime/realtime ratio), expressed as a percentage. It will not add
up to 100% unless you are lucky. (alias pcpu).
%mem %MEM ratio of the process's resident set size to the physical memory on the machine, expressed as a
percentage. (alias pmem).
args COMMAND command with all its arguments as a string. Modifications to the arguments may be shown. The output in
this column may contain spaces. A process marked <defunct> is partly dead, waiting to be fully
destroyed by its parent. Sometimes the process args will be unavailable; when this happens, ps will
instead print the executable name in brackets. (alias cmd, command). See also the comm format keyword,
the -f option, and the c option.
When specified last, this column will extend to the edge of the display. If ps can not determine
display width, as when output is redirected (piped) into a file or another command, the output width
is undefined (it may be 80, unlimited, determined by the TERM variable, and so on). The COLUMNS
environment variable or --cols option may be used to exactly determine the width in this case. The w
or -w option may be also be used to adjust width.
blocked BLOCKED mask of the blocked signals, see signal(7). According to the width of the field, a 32 or 64-bit mask
in hexadecimal format is displayed. (alias sig_block, sigmask).
bsdstart START time the command started. If the process was started less than 24 hours ago, the output format is
" HH:MM", else it is "Mmm dd" (where Mmm is the three letters of the month). See also lstart, start,
start_time, and stime.