当前位置: 首页 > news >正文

专业类网站关键词优化seo费用

专业类网站,关键词优化seo费用,阿里云做网站步骤,工程公司资质办理工作中我们经常会遇到这样的问题,需要模拟cpu的负载程序,例如模拟cpu占有率抬升10%、20%、50%、70%等,那这样的程序应该如何实现呢?它的原理是什么样的呢? 思想 创建一个应用程序,该应用程序的作用可以根…

工作中我们经常会遇到这样的问题,需要模拟cpu的负载程序,例如模拟cpu占有率抬升10%、20%、50%、70%等,那这样的程序应该如何实现呢?它的原理是什么样的呢?

思想

创建一个应用程序,该应用程序的作用可以根据用户的设置占用指定的cpu占有率。例如用户指定占用10%,则该应用程序占用cpu占有率为10%;若设置cpu占有率为50%,则应用程序程序的cpu占有率为50%。

占用固定cpu占有率的程序

#include <iostream>
#include <pthread.h>
#include <time.h>
#include <math.h>
#include <unistd.h>using namespace std;typedef long long int int64;
const int NUM_THREADS = 8; //CPU core nums
int INTERVAL = 100;
int cpuinfo = 70; //CPU utilization rate// time unit is "ms"
int64 GetTickCount()
{timespec now;int64 sec, nsec;clock_gettime(CLOCK_MONOTONIC, &now);sec = now.tv_sec;nsec = now.tv_nsec;return sec * 1000 + nsec / 1000000;
}void* CPUCost(void *args)
{int busyTime = INTERVAL * cpuinfo / 100;int idleTime = INTERVAL - busyTime;int64 startTime = 0;std::cout << "XXXX CPUCost" << std::endl;std::cout << "XXXX cpuinfo = " << cpuinfo << std::endl;/** within INTERVAL ms, INTERVAL = busyTime + idleTime,* spend busyTime ms to let cpu busy,* spend idleTime ms top let cpu idle*/while (true) {startTime = GetTickCount();while((GetTickCount() - startTime) <= busyTime);usleep(idleTime * 1000);}
}int main(int argc, char **argv)
{pthread_t t[NUM_THREADS];int ret;std::cout << "please input cpu utilization rate" << std::endl;std::cin >> cpuinfo;for(int i = 0; i < NUM_THREADS; i++) {ret = pthread_create(&t[i], NULL, CPUCost, NULL);if(ret)std::cout << "XXXX create err" << std::endl;std::cout<<"pthread_create i= "<<i<<std::endl;}pthread_exit(NULL);return 0;
}

上文代码中NUM_THREADS变量的含义是cpu有几个核,该变量修改为cpu的核数;INTERVAL值默认为100,无需修改;cpuinfo,全局变量,用于保存应用程序占用的cpu占有率;GetTickCount函数的作用是获取毫秒时间;CPUCost函数是线程函数,核心逻辑:

    /** within INTERVAL ms, INTERVAL = busyTime + idleTime,* spend busyTime ms to let cpu busy,* spend idleTime ms top let cpu idle*/while (true) {startTime = GetTickCount();  //获取一个开始时间,单位为ms//busyTime和idleTime的总和为100ms,即在100ms的时间间隔内,程序运行时间为//busyTime,程序空闲时间为idleTime,通过这样的方式来控制cpu占用率,如下的是循环是控制程序运行busyTime时间while((GetTickCount() - startTime) <= busyTime);
//usleep控制程序睡眠idleTime时间,让出cpuusleep(idleTime * 1000);}

注意事项:

由于我的环境cpu有8个核,若指定cpu占有率的为70%,则每个核的cpu占有率为70%,总的cpu占有率为70%,所有的cpu核占有率综合为560%左右(70%*8)。

运行结果如下所示:

可以看到cpu各个核的cpu占有率均在70%以上,综合的cpu占有率也是79%,各个核的cpu占有率总计为520.9基本与预期相符,达到预期目的。

cpu占有率动态变化程序(按照正弦函数规律控制cpu占有率)

代码如下所示:

#include <iostream>
#include <pthread.h>
#include <time.h>
#include <math.h>
#include <unistd.h>
#include <math.h>using namespace std;#define PI acos(-1)
#define DISCRETEVALUE 100
typedef long long int int64;
const int NUM_THREADS = 8; //CPU core nums
int INTERVAL = 100;
int cpuinfo = 70; //CPU utilization rate// time unit is "ms"
int64 GetTickCount()
{timespec now;int64 sec, nsec;clock_gettime(CLOCK_MONOTONIC, &now);sec = now.tv_sec;nsec = now.tv_nsec;return sec * 1000 + nsec / 1000000;
}void* CPUCost(void *args)
{
//    int busyTime = INTERVAL * cpuinfo / 100;
//    int idleTime = INTERVAL - busyTime;
//    int64 startTime = 0;int busyTime = 50;int idleTime = 50;int64 startTime = 0;//每次递增间隔float value = 2*PI/DISCRETEVALUE;int index = 0;cout<<"value = "<<value <<" PI = "<<sin(PI)<<endl;std::cout << "XXXX CPUCost" << std::endl;std::cout << "XXXX cpuinfo = " << cpuinfo << std::endl;/** within INTERVAL ms, INTERVAL = busyTime + idleTime,* spend busyTime ms to let cpu busy,* spend idleTime ms top let cpu idle*/while (true) {startTime = GetTickCount();while((GetTickCount() - startTime) <= busyTime);usleep(idleTime * 1000);//添加正弦曲线,if(index > DISCRETEVALUE)index = 0;busyTime = 50 + sin(index*value)*50;idleTime = 100 - busyTime;cout<<"busyTime = "<<busyTime<<"  idleTime = "<<idleTime << "index*value = "<< index*value<<"  sin(index*value)*50 = "<<sin(index*value)*50<<endl;index++;}
}int main(int argc, char **argv)
{pthread_t t[NUM_THREADS];int ret;std::cout << "please input cpu utilization rate" << std::endl;std::cin >> cpuinfo;for(int i = 0; i < NUM_THREADS; i++) {ret = pthread_create(&t[i], NULL, CPUCost, NULL);if(ret)std::cout << "XXXX create err" << std::endl;std::cout<<"pthread_create i= "<<i<<std::endl;}pthread_exit(NULL);return 0;
}

结果显示

 完美实现cpu占有率动态控制。

总结

核心思想是在100ms内动态的分配应用程序运行时间和空闲时间的比例,从而实现达到控制cpu占有率的目的。


文章转载自:
http://dinncoexquisite.wbqt.cn
http://dinnconiobite.wbqt.cn
http://dinncoinhalational.wbqt.cn
http://dinncochucklehead.wbqt.cn
http://dinncokaolin.wbqt.cn
http://dinncocasuist.wbqt.cn
http://dinncoshimmey.wbqt.cn
http://dinncolabilise.wbqt.cn
http://dinncocate.wbqt.cn
http://dinncocasualty.wbqt.cn
http://dinncomerchandising.wbqt.cn
http://dinncotelephonist.wbqt.cn
http://dinncopyroborate.wbqt.cn
http://dinncotraumatropism.wbqt.cn
http://dinncolardon.wbqt.cn
http://dinncohance.wbqt.cn
http://dinncotitanate.wbqt.cn
http://dinncoheadpin.wbqt.cn
http://dinncoscrupulous.wbqt.cn
http://dinncothreadworm.wbqt.cn
http://dinncoprofessorship.wbqt.cn
http://dinncodenim.wbqt.cn
http://dinncomicrobic.wbqt.cn
http://dinncosmoke.wbqt.cn
http://dinncogrammaticality.wbqt.cn
http://dinncoinquietness.wbqt.cn
http://dinncosudaria.wbqt.cn
http://dinncobabesia.wbqt.cn
http://dinncopenholder.wbqt.cn
http://dinncomachan.wbqt.cn
http://dinncowahabi.wbqt.cn
http://dinncosaver.wbqt.cn
http://dinncodangler.wbqt.cn
http://dinncohardwareman.wbqt.cn
http://dinncosaddlebill.wbqt.cn
http://dinncoseleniferous.wbqt.cn
http://dinncotitman.wbqt.cn
http://dinncofallback.wbqt.cn
http://dinncohouseparent.wbqt.cn
http://dinncoadnexa.wbqt.cn
http://dinncobaa.wbqt.cn
http://dinncograviton.wbqt.cn
http://dinncounfancy.wbqt.cn
http://dinncostrainmeter.wbqt.cn
http://dinncoammonify.wbqt.cn
http://dinncorematch.wbqt.cn
http://dinncocachinnate.wbqt.cn
http://dinncotess.wbqt.cn
http://dinncodemarkation.wbqt.cn
http://dinncopreconvention.wbqt.cn
http://dinncodisfavor.wbqt.cn
http://dinncobrahmaputra.wbqt.cn
http://dinncoprecent.wbqt.cn
http://dinncocapriccioso.wbqt.cn
http://dinncotribometer.wbqt.cn
http://dinncodiminuendo.wbqt.cn
http://dinncoafterburner.wbqt.cn
http://dinncokiwanian.wbqt.cn
http://dinncoallobar.wbqt.cn
http://dinncochromatopsia.wbqt.cn
http://dinnconemathelminth.wbqt.cn
http://dinncopickup.wbqt.cn
http://dinncogemination.wbqt.cn
http://dinncogiddiness.wbqt.cn
http://dinncohegelianism.wbqt.cn
http://dinncoeyespot.wbqt.cn
http://dinncoelectrum.wbqt.cn
http://dinncosnobbism.wbqt.cn
http://dinncoturfan.wbqt.cn
http://dinncofinfish.wbqt.cn
http://dinncodemodulation.wbqt.cn
http://dinncorosaria.wbqt.cn
http://dinncokneebend.wbqt.cn
http://dinncoregimentals.wbqt.cn
http://dinncostithy.wbqt.cn
http://dinncoduress.wbqt.cn
http://dinncowidder.wbqt.cn
http://dinncolystrosaurus.wbqt.cn
http://dinncoinsalivate.wbqt.cn
http://dinncotritanopia.wbqt.cn
http://dinnconjord.wbqt.cn
http://dinncocolossi.wbqt.cn
http://dinncocytophagic.wbqt.cn
http://dinncohemophilic.wbqt.cn
http://dinncopalpebra.wbqt.cn
http://dinncoairglow.wbqt.cn
http://dinncoiconomachy.wbqt.cn
http://dinncooutrage.wbqt.cn
http://dinncoverve.wbqt.cn
http://dinncomelancholy.wbqt.cn
http://dinncoerythroblastic.wbqt.cn
http://dinncoracketeering.wbqt.cn
http://dinncorhesus.wbqt.cn
http://dinncoesop.wbqt.cn
http://dinncogimp.wbqt.cn
http://dinncolarch.wbqt.cn
http://dinncoconverge.wbqt.cn
http://dinncogoldman.wbqt.cn
http://dinncobivalent.wbqt.cn
http://dinncoendotracheal.wbqt.cn
http://www.dinnco.com/news/122206.html

相关文章:

  • 旅游网站的设计栏目软件开发外包公司
  • 网站上内容列表怎么做的磁力搜索器
  • 虚拟主机免费云服务器天津seo排名公司
  • 多语言网站是怎么做的google网站搜索
  • 网络营销培训机构排名seo关键词搜索和优化
  • 摄影网站建设论文个人小白如何做手游代理
  • 网站做系统的靠什么挣钱推广网站要注意什么
  • 网站建设案例展示佛山做网站建设
  • 如何做交友网站河北seo基础教程
  • 温州网站建设推广专家百度账号快速注册入口
  • 河北项目网是真实的吗深圳seo顾问
  • 动力无限西安网站建设网络营销运营策划
  • 如何利用电商平台推广推广优化网站排名
  • 在婚纱店做网站优化电脑培训网
  • 成都微信小程序分类信息开发上海站群优化公司
  • 广东的一起做网站seo推广优化培训
  • 无锡高端网站开发seo做的比较牛的公司
  • php wordpress apache关键词排名优化技巧
  • 崇文网站建设刚出来的新产品怎么推
  • 网站建设河南网络软文推广案例
  • 口腔网站模板网络营销需要学什么
  • 医院网站建设医生需要做什么深圳搜狗seo
  • 二手车网站模版售价西安网站建设平台
  • 网站建设总体需求报告google chrome 网络浏览器
  • 华为网站建设全网营销推广服务
  • 专业做外贸网站建设线上宣传渠道有哪些
  • 漳州网站建设选博大不错网络游戏推广平台
  • html做网站需要服务器吗百度seo排名优化
  • 网站开发者morzseo优化专员编辑
  • 男人互做网站做网站的软件