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

梁山网站开发建设股公司网站

梁山网站开发,建设股公司网站,seo网站编辑是做什么的,小说关键词生成器Redis短连接的性能优化 1. 问题 通过历史监控我们可以发现用户在频繁使用短连接的时候Redis的cpu使用率有显著的上升 2. 排查 通过扁鹊查看但是Redis的cpu运行情况如下 从扁鹊我们可以看到Redis在freeClient的时候会频繁调用listSearchKey#xff0c;并且该函数占用了百分…Redis短连接的性能优化 1. 问题 通过历史监控我们可以发现用户在频繁使用短连接的时候Redis的cpu使用率有显著的上升 2. 排查 通过扁鹊查看但是Redis的cpu运行情况如下 从扁鹊我们可以看到Redis在freeClient的时候会频繁调用listSearchKey并且该函数占用了百分30左右的调用量如果我们可以优化降低该调用短连接性能将得到具体提升。 3. 优化 通过以上分析我们可以知道Redis在释放链接的时候频繁调用了listSearchKey通过查看Redis关闭客户端源码如下 void freeClient(redisClient *c) { listNode *ln; /* If this is marked as current client unset it */ if (server.current_client c) server.current_client NULL;/* If it is our master thats beging disconnected we should make sure* to cache the state to try a partial resynchronization later.** Note that before doing this we make sure that the client is not in* some unexpected state, by checking its flags. */ if (server.master c-flags REDIS_MASTER) {redisLog(REDIS_WARNING,Connection with master lost.);if (!(c-flags (REDIS_CLOSE_AFTER_REPLY|REDIS_CLOSE_ASAP|REDIS_BLOCKED| REDIS_UNBLOCKED))){replicationCacheMaster(c);return;} }/* Log link disconnection with slave */ if ((c-flags REDIS_SLAVE) !(c-flags REDIS_MONITOR)) {redisLog(REDIS_WARNING,Connection with slave %s lost.,replicationGetSlaveName(c)); }/* Free the query buffer */ sdsfree(c-querybuf); c-querybuf NULL;/* Deallocate structures used to block on blocking ops. */ if (c-flags REDIS_BLOCKED)unblockClientWaitingData(c); dictRelease(c-bpop.keys);freeClientArgv(c);/* Remove from the list of clients */ if (c-fd ! -1) {ln listSearchKey(server.clients,c);redisAssert(ln ! NULL);listDelNode(server.clients,ln); }/* When client was just unblocked because of a blocking operation,* remove it from the list of unblocked clients. */ if (c-flags REDIS_UNBLOCKED) {ln listSearchKey(server.unblocked_clients,c);redisAssert(ln ! NULL);listDelNode(server.unblocked_clients,ln); } ... ... ... /* Release other dynamically allocated client structure fields,* and finally release the client structure itself. */ if (c-name) decrRefCount(c-name); zfree(c-argv); freeClientMultiState(c); sdsfree(c-peerid); if (c-pause_event 0) aeDeleteTimeEvent(server.el, c-pause_event); zfree(c);} 从源码我们可以看到Redis在释放链接的时候遍历server.clients查找到对应的redisClient对象然后调用listDelNode把该redisClient对象从server.clients删除,代码如下: /* Remove from the list of clients */ if (c-fd ! -1) { ln listSearchKey(server.clients,c); redisAssert(ln ! NULL); listDelNode(server.clients,ln); } 查看server.clients为List结构而redis定义的List为双端链表我们可以在createClient的时候将redisClient的指针地址保留再freeClient的时候直接删除对应的listNode即可无需再次遍历server.clients代码优化如下 3.1 createClient修改 redisClient *createClient(int fd) { redisClient *c zmalloc(sizeof(redisClient)); /* passing -1 as fd it is possible to create a non connected client.* This is useful since all the Redis commands needs to be executed* in the context of a client. When commands are executed in other* contexts (for instance a Lua script) we need a non connected client. */ if (fd ! -1) {anetNonBlock(NULL,fd);anetEnableTcpNoDelay(NULL,fd);if (server.tcpkeepalive)anetKeepAlive(NULL,fd,server.tcpkeepalive);if (aeCreateFileEvent(server.el,fd,AE_READABLE,readQueryFromClient, c) AE_ERR){close(fd);zfree(c);return NULL;} }... if (fd ! -1) {c-client_list_node listAddNodeTailReturnNode(server.clients,c); } return c;} 3.2 freeClient修改 freeClient修改如下 /* Remove from the list of clients */ if (c-fd ! -1) { if (c-client_list_node ! NULL) listDelNode(server.clients,c-client_list_node); } 3.3 优化结果 在同一台物理机上启动优化前后的Redis分别进行压测压测命令如下 redis-benchmark -h host -p port -k 0 -t get -n 100000 -c 8000 其中-k 代表使用短连接进行测试 原生Redis-server结果: 99.74% 963 milliseconds 99.78% 964 milliseconds 99.84% 965 milliseconds 99.90% 966 milliseconds 99.92% 967 milliseconds 99.94% 968 milliseconds 99.99% 969 milliseconds 100.00% 969 milliseconds 10065.42 requests per second 优化后Redis-server结果 99.69% 422 milliseconds 99.72% 423 milliseconds 99.80% 424 milliseconds 99.82% 425 milliseconds 99.86% 426 milliseconds 99.89% 427 milliseconds 99.94% 428 milliseconds 99.96% 429 milliseconds 99.97% 430 milliseconds 100.00% 431 milliseconds 13823.61 requests per second 我们可以看到优化之后的Redis-server性能在短连接多的场景下提升了百分30%以上。
http://www.dnsts.com.cn/news/224389.html

相关文章:

  • 广州网站关键排名响应网站和模板网站
  • 做外贸必备网站网页视频怎么下载到本地
  • 做的网站如何放在电脑上成都品牌设计策划
  • 网站运营建设岗位职责防城港网站制作
  • 企业如何建公司网站上海做网站的月薪
  • 把网站做进微信公众号网络推广途径
  • 旅游网站建设与网页设计意义南翔企业网站开发建设
  • 天水市建设局网站公告手游传奇开服网站
  • 网站悬浮图标怎么做有的网站打不开是什么原因
  • 公司网站的ftp是什么鸿梦社区wordpress
  • 建网站怎么样才能流畅北京seo学校
  • 广州巨腾建网站公司开发公司工程管理中心管理制度
  • 福建漳州建设局网站深圳公司免费网站建设
  • 国外域名。国内网站福州定制网站开发
  • 国外网站用什么dns苏州注册公司网上申请入口
  • 网站优化潍坊在线平面设计招聘
  • 贵州省建设厅建筑质监站网站wordpress图片加速
  • 网站优化内链怎么做注册公司网站怎么做
  • 微官网与网站的区别大作业网站建设方案
  • 泉州网站开发济南网站建设模板
  • 个人网站免费域名获取十大网站排行榜
  • 福田专门做网站推广公司十大农业网站
  • 建设工程现行标准查询网站网站开发职业类别代码
  • 做化工贸易要用那些网站推广建立公司网站需要注意什么
  • 网站上面如何加入视频做网站哪些好
  • 做网站要备案吗wordpress如何加友链
  • 织梦网站做自动生成地图网站备案查询 api
  • 网站改版设计费进什么科目wordpress类似软件
  • 所有网站打不开网络营销是什么 能做什么
  • 网站建设合同严瑾南宁行业平台开发公司