{"id":17266747,"url":"https://github.com/yangbodong22011/kioskcached","last_synced_at":"2025-10-04T07:57:13.730Z","repository":{"id":136432285,"uuid":"79231746","full_name":"yangbodong22011/kioskcached","owner":"yangbodong22011","description":"一款内存缓存型数据库，单线程架构，旨在提高get和set性能。","archived":false,"fork":false,"pushed_at":"2017-04-20T01:17:48.000Z","size":231,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-24T07:08:14.492Z","etag":null,"topics":["memcached","nosql","redis"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yangbodong22011.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-01-17T13:45:34.000Z","updated_at":"2022-09-13T16:44:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"3f4b6929-2a66-4237-af9f-6746a60f50e3","html_url":"https://github.com/yangbodong22011/kioskcached","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yangbodong22011/kioskcached","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangbodong22011%2Fkioskcached","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangbodong22011%2Fkioskcached/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangbodong22011%2Fkioskcached/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangbodong22011%2Fkioskcached/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yangbodong22011","download_url":"https://codeload.github.com/yangbodong22011/kioskcached/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangbodong22011%2Fkioskcached/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278283448,"owners_count":25961311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["memcached","nosql","redis"],"created_at":"2024-10-15T08:06:52.058Z","updated_at":"2025-10-04T07:57:13.707Z","avatar_url":"https://github.com/yangbodong22011.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kioskCached\n\n\n        一款内存缓存型数据库，实现了基础的增、删、改、查功能。由于Memcached是多线程网络模型，锁的使用势必会降低性能。\n        本项目旨在使用单线程模型提供高性能的GET/SET方法。项目采用C/C++开发，参考Redis网络架构设计自行封装AeEvent\n        事件处理框架，单线程IO多路复用模型避免了锁的争用，保证了操作的原子性。使用C++11 unordered_set管理内存数据\n        结构。采用Memcached客户端协议作为标准协议。\n\n\n## 一、对比Memcached和Redis\n\n### 1：测试环境： \n\n\u003e OS ： RedHat 7 \nKernel : Linux version 3.10.0-514.el7.x86_64   \n\u003e\nCPU : Intel(R) Core(TM) i5 CPU M 520  @ 2.40GHz  \n\u003e\nMem : 8G\n\u003e\n//备注：除了测试三个数据库的QPS，我还使用Google的  [gperftools](http://www.cnblogs.com/caosiyang/archive/2013/01/25/2876244.html)  工具我的项目做了`CPU PROFILER`，找出了代码中占用CPU最多的函数，并考虑优化它。\n\n### 2 ：测试条件：\n- 100000条 key-value 数据，每条大概100字节大小\n\n\n### 3： Memcached 测试结果\n\n- set 性能：22891.8 QPS\n\n![](/image/memcached_set.png)\n\n- get 性能：25262.8 QPS\n\n![](/image/memcached_get.png)\n\n### 4： Redis 测试结果\n\n- set 性能：30156.82 QPS\n\n![](/image/redis_set.png)\n\n- get 性能：31007.75 QPS\n\n![](/image/redis_get.png)\n\n\n### 5： Kioskcached 测试结果\n\n\n### （1）当value的值为**100字节**时 ： QPS  = 316275\n\n![这里写图片描述](http://img.blog.csdn.net/20170309085017711)\n\n使用`gperftools`找出使用CPU前几位的函数为：[output_100.txt](https://github.com/yangbodong22011/kioskcached/blob/master/test/TestFile/output_100.txt)\n\n![这里写图片描述](http://img.blog.csdn.net/20170309004137410)\n\n```\n$ cat output.txt \n\nTotal: 259 samples\n      34  13.1%  13.1%       56  21.6% std::_Hashtable::_M_find_before_node\n      21   8.1%  21.2%       22   8.5% _int_malloc\n      17   6.6%  27.8%       23   8.9% std::_Hashtable::_M_rehash_aux\n\n...... \n\n```\n\n输出结果说明（按照列数往下）：\n\n\n\n\n| 序号 | 说明 |\n| --- | --- |\n|1| 分析样本数量（不包含其他函数调用）|\n|2|分析样本百分比（不包含其他函数调用）| \n|3| 目前为止的分析样本百分比（不包含其他函数调用）|\n|4|分析样本数量（包含其他函数调用）|\n|5|分析样本百分比（包含其他函数调用）|\n|6|函数名|    \n\n  \n \n\n### （2）当value的值为**1000字节**时 ： QPS  = 203203\n\n![这里写图片描述](http://img.blog.csdn.net/20170309085142451)\n\n使用`gperftools`找出使用CPU前几位的函数为：[output_1000.txt](https://github.com/yangbodong22011/kioskcached/blob/master/test/TestFile/output_1000.txt)\n```\nTotal: 426 samples\n      78  18.3%  18.3%       78  18.3% __read_nocancel\n      64  15.0%  33.3%       70  16.4% _int_malloc\n      28   6.6%  39.9%       57  13.4% std::_Hashtable::_M_find_before_node\n\n......\n可以发现与100字节相比较，此时read系统调用占用CPU已经成为了第一。\n```\n\n\n### （3）当value的值为10000字节时 ： QPS  = 167266\n\n![这里写图片描述](http://img.blog.csdn.net/20170309085237043)  \n\n\n\n使用`gperftools`找出使用CPU前几位的函数为：[output_10000.txt](https://github.com/yangbodong22011/kioskcached/blob/master/test/TestFile/output_10000.txt)\n```\nTotal: 521 samples\n     102  19.6%  19.6%      102  19.6% __read_nocancel\n      79  15.2%  34.7%       83  15.9% _int_malloc\n      42   8.1%  42.8%       42   8.1% __GI_epoll_wait\n      29   5.6%  48.4%       52  10.0% std::_Hashtable::_M_find_before_node\n      \nmalloc 还是我们的难题和瓶颈。\n......  剩余的省略\n\n```\n\n\n\n### （4）： 总结 \n\n通过上面的测试，可以发现下面这几个函数是主要的CPU性能瓶颈\n\n```\n_int_malloc\nstd::_Hashtable::_M_find_before_node\nstd::_Hashtable::_M_rehash_aux\n__read_nocancel\n```\n\n这些都消耗非常多的CPU，要是优化的话先从它们入手，我自己可以处理的是`malloc` 和 `std::_Hashtable::_M_find_before_node`。\n\n\n# 二、改进方法\n\n- 使用tcmalloc等第三方性能优于glibc ptmalloc的内存分配器。[已完成,性能提升%16](http://blog.csdn.net/yangbodong22011/article/details/61195268)\n- 使用多个unordered_set将数据分片存取.[正在完成]\n- 重新找寻Hash函数，做适配替代目前的Hash函数。[未完成]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyangbodong22011%2Fkioskcached","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyangbodong22011%2Fkioskcached","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyangbodong22011%2Fkioskcached/lists"}