移动移动手机主副卡办理不在同一个手机上怎么共享流量

苹果/安卓/wp
积分 125, 距离下一级还需 20 积分
权限: 自定义头衔
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡下一级可获得
道具: 匿名卡
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
苦逼签到天数: 6 天连续签到: 1 天[LV.2]偶尔看看I
RT,算个模拟过程,半个小时了,一直在算,可是CPU使用率一直只有40%不到,是什么原因?求能够快点的办法。谢谢!
支持楼主:、
购买后,论坛将把您花费的资金全部奖励给楼主,以表示您对TA发好贴的支持
载入中......
貌似只支持单核
李会超 发表于
貌似只支持单核好的谢谢
R在2.14版本之后就内置了parallel包,强化了R的并行计算能力,只是你跑的计算程序需要用parallel包的功能做过并行计算优化才会利用多核
无限扩大经管职场人脉圈!每天抽选10位免费名额,现在就扫& 论坛VIP& 贵宾会员& 可免费加入
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
京ICP证090565号
论坛法律顾问:王进律师[2.PL] Programming ART
本文的目的不是贴代码,而是希望通过较浅显的文字,讲明白求解CPU使用率的方法.所以急功近利的人并不适合阅读本文.
其实,获取Windows系统的CPU使用率已经是老问题了.大概是有以下几种方法:
1.查询注册表(HKEY_DYN_DATA),这个适用于Win9x,太老的东西,觉得现在基本没有什么必要再去了解它.2.利用性能计数器(PDH)接口查询,支持NT系统,功能全面,用起来也方便,不过不是本文讨论的重点,只提一下.3.利用Windows NT Native API(以下简称Native API,它们是ntdll.dll中的一些未公开API)来获取数据并计算CPU使用率.(本文主要讲它)(也许还有其它的吧?...)
利用Native API来获取CPU使用率的方法,网上已有很多介绍的文章,也不乏代码.不过,现在双核(甚至更多)的CPU比较普及,然而网上的文章主要介绍了获取总的CPU使用率的方法,我却未找到关于怎样使用Native API来获取多核中每个单独核心CPU使用率的方法的相关文章.也许是我视力不好,没注意看到也说不定.
不能发扬"拿来主义",那就应该"自己动手",才能"丰衣足食".学习了前辈文章的一些方法,自己再仔细研究了Native API(对此有兴趣的朋友可以去读读&&Windows NT/2000 Native API Reference&&),终于找到了支持多核的方法.在此拿出来和大家分享.
[什么是CPU使用率?]
首先,我要谈到一个概念:"什么是CPU使用率"(认为明白此概念的朋友可以跳过这节),为什么要强调它?是因为我发现有些人误解了这个概念,而这样的话,就不能正确地设计出CPU使用率的计算方法.我们在Windows的任务管理器中可以实时地看到CPU使用率,每1秒(默认刷新频率是1秒/次)都在变化,因而某些人可能就会误认为,CPU使用率是一个瞬时值,在任何一个时刻它都有一个值,那么这些人可能会说:"在5分12秒这一时刻,CPU使用率为10%."这样的话,那就错了!实际上,了解一点CPU工作原理的人应该知道,在某一个时刻,CPU只有一个状态:"工作"或者"空闲",即0和1,照前面的理解,岂不是使用率只有0%和100%这两个值了吗?显然不对.对CPU使用率的正确理解应该是:在某一个时间段(T)中,CPU总共工作的时间(W)占这个整个时间段的百分比.即W/T*100%.可以对这个公式变更一下,如果我们知道的是这个时间段中CPU的空闲(没有工作)时间(I),那也可以通过(T-I)/T*100%或(1-I/T)*100%来算出CPU使用率.因此,正确的说法应该是:"在5分12秒到5分13秒这1秒钟内,CPU使用率为10%."这样理解就对了!
[CPU使用率计算公式]
通过了对CPU使用率这一概念的认识和理解,我们能得出CPU使用率的计算公式如下:T:某个时间段(就是要计算这个时间段的CPU使用率)W:在这个时间段中CPU处于工作状态的时间I:在这个时间段中CPU处于空闲状态的时间CPU%=W/T*100% 或CPU%=(T-I)/T*100%显然,只要知道了上面公式中的相关因素(T和W,或者,T和I)的值,就能计算出CPU使用率.
[代码相关说明]
因为最近工作中都在使用Delphi(跟VC比的话,用着确实舒服,个人感觉),下面就以Delphi代码简要说明使用Native API求解CPU使用率的过程.主要用到NtQuerySystemInformation函数,以及一些相关枚举/结构等,具体的声明/定义略掉,因为这些都能很容易在网上或书上(&&Windows NT/2000 Native API Reference&&)找到,因此就不写在这里占据篇幅了.
先简单列出会用到的相关函数/枚举/结构等.函数:NtQuerySystemInformation枚举:SYSTEM_INFORMATION_CLASS结构:SYSTEM_BASIC_INFORMATION&&&& SYSTEM_PERFORMANCE_INFORMATION&&&& SYSTEM_TIME_OF_DAY_INFORMATION&&&& SYSTEM_PROCESSOR_TIMES
[计算总的CPU使用率]
还是先说怎么求总的CPU使用率.因为前面已经提到,这个在网上已经讲得很多了,但为了本文的完整性,这里就再COPY一下前辈们的知识,当然也有一些自己的补充和完善.
通过Native API我们可以获取到公式中的T和I,方法分别如下:view plaincopy to clipboardprint?{获取T}& var& & stodi: SYSTEM_TIME_OF_DAY_INFORMATION;&& begin& & NtQuerySystemInformation(&& &&& SystemTimeOfDayInformation,&& &&& @stodi,&& &&& SizeOf(SYSTEM_TIME_OF_DAY_INFORMATION),&& &&& nil& & );&& & {stodi.CurrentTime就是我们需要的,它是LARGE_INTEGER格式的时间,& & 描述了系统从开机到现在运行的累计总时间,单位为100纳秒.}& && {获取I}& var& & spi: SYSTEM_PERFORMANCE_INFORMATION;&& begin& & NtQuerySystemInformation(&& &&& SystemPerformanceInformation,&& &&& @spi,&& &&& SizeOf(SYSTEM_PERFORMANCE_INFORMATION),&& &&& nil& & );&& & {spi.IdleTime就是我们需要的,它是LARGE_INTEGER格式的时间,& & 描述了CPU开机到现在所累计的总的空闲时长,单位为100纳秒.}& & {获取T}var& stodi: SYSTEM_TIME_OF_DAY_INFORMATION;begin& NtQuerySystemInformation(&&& SystemTimeOfDayInformation,&&& @stodi,&&& SizeOf(SYSTEM_TIME_OF_DAY_INFORMATION),&&& nil& );& {stodi.CurrentTime就是我们需要的,它是LARGE_INTEGER格式的时间,& 描述了系统从开机到现在运行的累计总时间,单位为100纳秒.}{获取I}var& spi: SYSTEM_PERFORMANCE_INFORMATION;begin& NtQuerySystemInformation(&&& SystemPerformanceInformation,&&& @spi,&&& SizeOf(SYSTEM_PERFORMANCE_INFORMATION),&&& nil& );& {spi.IdleTime就是我们需要的,它是LARGE_INTEGER格式的时间,& 描述了CPU开机到现在所累计的总的空闲时长,单位为100纳秒.}通过上面的方法,我们获取到的T和I都是从开机起计时的累计总时长,而我们这里需要的只是某一个小小的时段(如前面说的"5分12秒到5分13秒这1秒钟内"),因此我们需要前/后取到两个时刻的值,后值减去前值,就得到我们想要的某个时段的时间长度了.
那么,我们的公式需要对T和I进行展开,如下:T=T后-T前I=I后-I前CPU%=(T-I)/T*100% 通过上面的方法,前/后间隔取值,再代入公式,就可以计算出某个时段CPU的使用率了.而在实际运用中,一般是设计循环过程(或使用TTimer),每隔一段时间,轮循地应用公式,就能依次不断地计算出相邻每个时段的CPU使用率,即实时效果.(具体的过程设计就略了吧)
然而,到目前这个公式还只能对单核CPU有效,多核的情况下会有问题.通过多种途径的对比分析,发现了这个问题因素是I.在多核情况下,这时I(即spi.IdleTime)的值是记录了全部CPU核心的总空闲时间的和(有点绕口).多核CPU在工作时是并行的,但计算它们时间还是做了累加,问题就在此!以双核CPU为例来做进一步的解释,spi.IdleTime(即I)的值是累加了2个CPU核心的空闲时间(两份),而stodi.CurrentTime(即T)则只是一份时间.所以修正的方法是T需要乘以当前CPU核心的数量(N).希望下面的简图能进一步帮助大家理解这个问题.view plaincopy to clipboardprint?{下图描述了10秒之间的情况,-表示空闲,+表示工作,每个符号的时间单位为1秒}& |========++| {CPU核心1,I1=8秒}& |======++++| {CPU核心2,I2=6秒}& {说明:两个CPU核心并行工作,实际经历了"两份"时间,I=I1+I2.}& |==========| {系统时段,T=10秒}& {说明:而记录的系统时段只有"一份",所以需要修正,乘以CPU核心数量}& {下图描述了10秒之间的情况,-表示空闲,+表示工作,每个符号的时间单位为1秒}|========++| {CPU核心1,I1=8秒}|======++++| {CPU核心2,I2=6秒}{说明:两个CPU核心并行工作,实际经历了"两份"时间,I=I1+I2.}|==========| {系统时段,T=10秒}{说明:而记录的系统时段只有"一份",所以需要修正,乘以CPU核心数量}那又该怎么获取CPU核心数量,依然使用Native API,如下:view plaincopy to clipboardprint?var& & sbi: SYSTEM_BASIC_INFORMATION;&& begin& & NtQuerySystemInformation(&& &&& SystemBasicInformation,&& &&& @sbi,&& &&& SizeOf(SYSTEM_BASIC_INFORMATION),&& &&& nil& & );&& & {CPU核心数量N=sbi.NumberProcessors}& & var& sbi: SYSTEM_BASIC_INFORMATION;begin& NtQuerySystemInformation(&&& SystemBasicInformation,&&& @sbi,&&& SizeOf(SYSTEM_BASIC_INFORMATION),&&& nil& );& {CPU核心数量N=sbi.NumberProcessors}所以,修正后的计算总的CPU使用率的公式如下:T=(T后-T前)*NI=I后-I前CPU%=(T-I)/T*100%
[计算多核中单个核心CPU使用率]
搞定了总的CPU使用率问题,现在再来讲讲怎么计算多核中单个核心CPU使用率.顺藤摸瓜,依葫画瓢,当然先把前面的公式套用过来,原理都是一样的嘛.那么公式理应如下:T[i]=T后[i]-T前[i]I[i]=I后[i]-I前[i]CPU%[i]=(T[i]-I[i])/T[i]*100% (i为CPU核心编号0,1,2...)注意,这里并没有使用乘以CPU核心数量N来修正时段T,因为这里已经是在针对"单个"核心的部分进行计算,所以不会存在上面的问题需要修正.或者说,单个核心部分,N肯定等于1.
这里的关键,同样是要获取T[i]和I[i].方法如下:view plaincopy to clipboardprint?{前提:先获取CPU核心数量N,因为下面需要用到.}& var& & i: I&& & spt: array of SYSTEM_PROCESSOR_TIMES; {这个数组对应多个CPU核心的相关数据}& begin& & SetLength(spt, N); {根据CPU核心数量N分配数组空间}& & NtQuerySystemInformation(&& &&& SystemProcessorTimes,&& &&& spt,&& &&& SizeOf(SYSTEM_PROCESSOR_TIMES),&& &&& nil& & );&& & for i := 0 to N - 1 do& & begin& && {通过分析数据得知:& &&& spt[i].KernelTime,spt[i].UserTime,spt[i].DpcTime和spt[i].InterruptTime的总和为累计系统总时间.& &&& stp[i].IdleTime为CPU运行的累计空闲时间.& &&& 因为也是累计时间,所以同样要使用"T=后-前"来计算.}& &&& & {前提:先获取CPU核心数量N,因为下面需要用到.}var& i: I& spt: array of SYSTEM_PROCESSOR_TIMES; {这个数组对应多个CPU核心的相关数据}begin& SetLength(spt, N); {根据CPU核心数量N分配数组空间}& NtQuerySystemInformation(&&& SystemProcessorTimes,&&& spt,&&& SizeOf(SYSTEM_PROCESSOR_TIMES),&&& nil& );& for i := 0 to N - 1 do& begin&& {通过分析数据得知:&&& spt[i].KernelTime,spt[i].UserTime,spt[i].DpcTime和spt[i].InterruptTime的总和为累计系统总时间.&&& stp[i].IdleTime为CPU运行的累计空闲时间.&&& 因为也是累计时间,所以同样要使用"T=后-前"来计算.}&最后代入公式就能计算出每个CPU核心的使用率,再设计循环过程(或使用TTimer),就能获取实时使用率了.
[性能计数器PDH]
如果直接使用性能计数器(PDH)接口来查询CPU使用率,是很方便的,所用到的查询串分别如下:'/Processor(_Total)/% Processor Time' 用于查询总的CPU使用率.'/Processor(%d)/%% Processor Time' 用于查询单个核心CPU使用率.用PDH还可以查询到更多的系统数据,比较全面.至于PDH的具体用法,就不再此多说,网上有,也可以查看MSDN,这里则点到为止.
本文来自CSDN博客,转载请标明出处:
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:598884次
积分:7327
积分:7327
排名:第2758名
原创:84篇
转载:105篇
评论:258条
本书版本输出到台湾地区,衷心感谢大家的支持。《深入理解Android内核设计思想》新书已在全国各大城市书店上市。
电子书店购买地址(不断增加中):
QQ群(专注于Android系统的分析与讨论)组:
文章:29篇
阅读:300709
(2)(3)(1)(1)(1)(1)(1)(20)(11)(1)(1)(1)(1)(6)(2)(2)(5)(13)(21)(6)(1)(7)(3)(4)(15)(14)(14)(4)(34)(1)2122人阅读
android(69)
根据最近的调研,Android整机的性能主要有如下方面:
本文着重介绍CPU相关数据的获取,在多核情况下,对每个CPU运行情况进行监控,获取相关的属性。
A. 当前主频,通过 cat&/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
获取,cpu0代表第一个CPU
B. 最大主频,通过 cat&/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq&获取,cpu0代表第一个CPU
C. 最小主频,通过 cat&/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq&获取,cpu0代表第一个CPU
D.使用率,通过 cat&/proc/stat 获取,文件内容如下:第一行代表整体CPU的使用情况,cpu0为第一个cpu的使用情况,不同的列数代表cpu的耗时情况,如第4列代表的就是空闲时间idle的值。
shell@V4:/ $ cat proc/stat
cat proc/stat
也就是说使用率我们无法直接获取,需要通过计算,具体的计算方式如下:
usage=(total-idel)/total
说明:使用率指得是cpu在某段时间内被使用的比率,因此事关两个时刻(t1、t2)的值。
分别需要在t1时刻和t2时刻获取total和idel
t1时刻获取: total_t1=所有值相加(同一行) idle_t1=第4个数值
t2时刻获取: total_t2=所有值相加(同一行) idle_t2=第4个数值
上述公式中的
total =&total_t2 -&total_t1
idle =&idle_t2 -&idle_t1
这是在国外的资料中说的,可是事实上运行的时候,这样的计算方式可能会出现负数,这边还有点疑问,如果哪位大神知道,麻烦指教。
此外,还有一些CPU的名称,核数信息等,此处不做详解。
下面给出一个类CPUManager,为了避免编码问题,直接用英文写的注释,如有语法错误。。。看懂就行
package com.performancemonitor.
import java.io.BufferedR
import java.io.F
import java.io.FileF
import java.io.FileInputS
import java.io.FileNotFoundE
import java.io.FileR
import java.io.IOE
import java.io.InputS
import java.io.InputStreamR
import java.text.DecimalF
import java.util.ArrayL
import java.util.HashM
import java.util.M
import java.util.regex.P
import android.util.L
public class CPUManager {
// CPU index
public int CPU_index = 0;
// sampling time in calculate usage
public int sample_fre = DataManager.sample_
public CPUManager(int index) {
this.CPU_index =
* Wether the CPU is online
true if it is online
public boolean isOnline() {
String result = &&;
InputStream in =
String[] args = { &/system/bin/cat&,
&/sys/devices/system/cpu/cpu& + CPU_index + &/online& };
cmd = new ProcessBuilder(args);
Process process = cmd.start();
in = process.getInputStream();
reader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String temp = &&;
while ((result = reader.readLine()) != null) {
temp = temp +
if (temp.equals(&1&)) {
in.close();
} catch (IOException ex) {
ex.printStackTrace();
* get the cpu's max frequency, return cpu0 max frequency by defalut
* &/system/bin/cat&
* &/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq&
public int getMaxCpuFreq() {
String result = &&;
String[] args = {
&/system/bin/cat&,
&/sys/devices/system/cpu/cpu& + CPU_index
+ &/cpufreq/cpuinfo_max_freq& };
if (!isOnline()) {
args[1] = &/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq&;
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[24];
while (in.read(re) != -1) {
result = result + new String(re);
in.close();
} catch (IOException ex) {
ex.printStackTrace();
result = &0&;
int max_fre = Integer.parseInt(result.trim()) / 1024;
return max_
get the cpu's min frequency,return cpu0 min frequency by defalut
public int getMinCpuFreq() {
String result = &&;
String[] args = {
&/system/bin/cat&,
&/sys/devices/system/cpu/cpu& + CPU_index
+ &/cpufreq/cpuinfo_min_freq& };
if (!isOnline()) {
args[1] = &/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq&;
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[24];
while (in.read(re) != -1) {
result = result + new String(re);
in.close();
} catch (IOException ex) {
ex.printStackTrace();
result = &-1&;
int min_fre = Integer.parseInt(result.trim()) / 1024;
return min_
* get the cpu's current frequency
public int getCurCpuFreq() {
String result = &&;
int cur_fre = 0;
if (!isOnline()) {
result = &0&;
FileReader fr = new FileReader(&/sys/devices/system/cpu/cpu&
+ CPU_index + &/cpufreq/scaling_cur_freq&);
BufferedReader br = new BufferedReader(fr);
String text = br.readLine();
result = text.trim();
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
cur_fre = Integer.parseInt(result) / 1024;
return cur_
* get the cpu name
public static String getCpuName() {
FileReader fr = new FileReader(&/proc/cpuinfo&);
BufferedReader br = new BufferedReader(fr);
String text = br.readLine();
String[] array = text.split(&:\\s+&, 2);
for (int i = 0; i & array. i++) {
return array[1];
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
* get the device's cpu num
public static int getNumCores() {
class CpuFilter implements FileFilter {
public boolean accept(File pathname) {
if (Pattern.matches(&cpu[0-9]&, pathname.getName())) {
File dir = new File(&/sys/devices/system/cpu/&);
File[] files = dir.listFiles(new CpuFilter());
return files.
} catch (Exception e) {
Log.e(&cxq&, &CPU Count: Failed.&);
e.printStackTrace();
* get the cpu usage using specified samplling time
public double getUsage() {
double usage = 0;
long total_start, total_
long idel_start, idel_
Map&String, Long& start_data = getCPUData();
idel_start = start_data.get(&idle&);
total_start = start_data.get(&total_time&);
Thread.sleep(sample_fre);
Map&String, Long& end_data = getCPUData();
idel_end = end_data.get(&idle&);
total_end = end_data.get(&total_time&);
double idel = idel_end - idel_
double total = total_end - total_
if (total == 0) {
usage = (total - idel) /
usage = Math.abs(usage * 100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
DecimalFormat df = new java.text.DecimalFormat(&#.00&);
usage = Double.parseDouble(df.format(usage));
* take a data snapshot avoid reading the old data, especially using for usage calculation
* @return Map it contains two values,(&total_time&,total_time) and (&idle&,idle);
public Map&String, Long& getCPUData() {
Map&String, Long& data = new HashMap&String, Long&();
ArrayList&Long& list = new ArrayList&Long&();
ArrayList&Long& list_defalut = new ArrayList&Long&();
for (int i = 0; i & 10; i++) {
list_defalut.add(0L);
String cpuCompare = &cpu& + CPU_
if (CPU_index == -1) {
cpuCompare = &cpu&;
String load = &&;
String[] temp =
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(&/proc/stat&)), 1000);
while ((load = reader.readLine()) != null) {
if (load.contains(cpuCompare)) {
load = &&;
reader.close();
if (load == null || load.equals(&&)) {
data.put(&total_time&, 0L);
data.put(&idle&, 0L);
temp = load.split(& &);
for (int i = 1; i & temp. i++) {
if (!temp[i].trim().equals(&&)) {
list.add(Long.parseLong(temp[i]));
} catch (IOException ex) {
Log.e(&CPU&, &IOException& + ex.toString());
data.put(&total_time&, 0L);
data.put(&idle&, 0L);
long total_time = 0;
for (int i = 0; i & list.size(); i++) {
total_time += list.get(i);
data.put(&total_time&, total_time);
data.put(&idle&, list.get(3));
如何使用?
如果要获取整个CPU的情况,则CPU_index=-1,该情况下无主频,如果要获取cpu0的情况,则在构造函数里面传0,以此类推
CPUManager total_cpu=new CPUManager(i);
&/p&&span style=&white-space:pre&& &/span&double usage=total_cpu.getUsage()
其他性能方面的数据获取,还有待补充。。。。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:118546次
积分:1790
积分:1790
排名:千里之外
原创:59篇
转载:15篇
评论:71条
(2)(2)(4)(3)(11)(2)(1)(3)(5)(2)(1)(4)(2)(1)(6)(6)(4)(5)(2)(2)(2)(1)(6)(4)你是否真的理解多核CPU系统的CPU使用率? - 菜鸟@大虾的个人空间 - 51Testing软件测试网 51Testing软件测试网-中国软件测试人的精神家园
你是否真的理解多核CPU系统的CPU使用率?
& 10:55:39
/ 个人分类:
When it comes to this analyzing and interpreting CPU metrics, there are many myths, wrong practices and misconceptions which prevail. In this post I would be touching upon a few critical issues and will try explaining the facts and best practices in detail.A wrong practiceFetching system wide CPU utilization of
node which is a symmetric multiprocessing system (SMP: A node having multiple cores/CPU’s sharing same memory, bus and IO)For most of the performance engineers or testers the common practice is to just fetch a system wide CPU utilization of a multi-core server node during load
and then start analyzing the result. Capturing a system wide CPU using tools like
on your UNIX/LINUX server nodes is highly misleading and could result in wrong interpretation of the cause of the bottleneck and henceforth deriving wrong solutions and futile efforts in an attempt to fix it.Different software’s such as a database or middleware have their own proprietary algorithms to deal with multi-core and multi-CPU’s and when you observe a system wide CPU utilization to be under the threshold limit during a load test it does not always mean that each individual core is equally loaded. Let me illustrate this: if you observe that a certain load testing tool is showing CPU utilization of 25% and if this particular server node has a quad core processor then it does not mean that all the cores are equally loaded with processes/threads. A single core might be utilized up to 100% and the rest might be left with a 100% idle task.The possibility of loading each individual core equally or proportionately depends a lot on the underlying parallelism of the application and also on whether the software under test has the capability to perform. intra query parallelization between cores available in the SMP; example:
supports intra query parallelization (i.e. splitting the work of one single query/independent query to two or more cores available in the SMP-Node) whereas
database does not support this feature as a result independent query will be processed using only one core even if the utilization of that core/CPU is exceeding the threshold)Another example: You might have observed while performing load tests that few transactions associated with slow queries mysteriously fails at the database node even though the CPU utilization is within threshold. Now, if you dig deeper into those slow queries and correlate it with CPU utilization of each individual core then you might be able to see that few cores are maxing out to 100% while the rest are well below the threshold which is the root cause of the problemAlso refer:Tools that I recommend to measure individual core/CPU’s utilization:Prstat(option –m or -mL): Available in Solaris operating system allows you to measure utilization of CPU on per-thread basis.mpstat:Available for linux/unix based OS (Note: Mpstat comes as a part of package of tools in Sysstat.)System Monitor:GUI oriented tool readily available in Red Hat
Operating systems.Also refer:A misconceptionGetting misled by 100% CPU utilization shown by the monitoring tool.You may be scratching and probably even banging your head against the monitor for not being able to find a feasible solution to fix the high CPU utilization problem observed on some of the server nodes. Your nodes might be experiencing 100% utilization even with an unimaginably less load.Well, the good news is that 100% utilization doesn’t always mean that CPU is being a performance bottleneck. Especially in case of a
or Linux operation system until and unless you see the ‘r’ value(process queue) in the vmstat output exceeding the total number of CPU count in the SMP-server node i.e. if r=5 but your SMP has only 4 CPU’s or cores then there is a bottleneck for sure.The whole idea behind queuing is that if the CPU or CPUs are not busy when a thread is put into the run/processor queue(r), it is immediately executed by a CPU. But if all of the available CPUs are busy executing threads, then the incoming threads will have to wait in the run queue/processor queue until there is a CPU available to process the waiting threads.That being said next time you see an alarmingly high value on the CPU metrics ask yourself this question: “What is CPU utilization?”Answer: CPU utilization = 100% – (% of time spent in idle task)If have understood the above equation you will never again misinterpret a CPU utilization metric.When it comes to comprehending the severity of a CPU related resource crunch many engineers forget that the fundamental purpose of process dispatchers or schedulers of an operating system is to make sure the CPU utilization is always high in the time of need. It doesn’t always imply that high CPU utilization slows down the transaction rate, for there are CPU’s available in the market such as the ‘ System z’ which is capable to work at 100% busy CPU state by exploiting the presence of diverse workloads. The type of workload which arrives at CPU queue greatly decides severity of high CPU utilization scenario. For instances, short lived, high priority processes triggered by 100s of concurrent users can affect the responsiveness of the application greater than a scenario where there are heterogeneous processes with different priorities arriving at the processor queue. A CPU operates at a certain clock speed and processes a unit of work at certain speed (Frequency); Whether the CPU is 10% utilized or 100% utilized the processor ideally should deliver the unit of work at the same speed, but since all processes share the same physical resources such as CPU buses, caches and CPs the CPU time per transaction increases as utilization of CPU becomes high. Speed of thread/process execution gets affected only when the total number of process/threads waiting for CPU exceeds the total number of processors available in the SMP/server node. Again, do not forget to watch the “r (run queue)” value closely next time during load testing/performance testing.Also refer:

我要回帖

更多关于 移动主卡电信副卡手机 的文章

 

随机推荐