首页 文章 精选 留言 我的

精选列表

搜索[1.2版本],共10022篇文章
优秀的个人博客,低调大师

C++ 基础库 CO 1.2 发布

Changes since v1.1 Bug 修复 fix#77 fix#83 修复协程库内部 Copool 未清空 Coroutine 中旧数据引起的 bug. coroutine 重构协程库,简化内部逻辑 增加单元测试 unitest/co,用于测试 Scheduler 内部逻辑. 新增 http 模块 实现http::Server类. 实现http::Client类. 实现so::easy(...)接口,用于快速创建静态 web server. hash 新增size_t murmur_hash(...)接口. fastring 支持std::hash<fastring>,std::unordered_map可以使用fastring作为 key. std::unordered_map<fastring, fastring> um; LruMap<fastring, fastring> lm; 新增lshift()接口,将字符串左移若干字节. fastring s = "hello"; s.lshift(2); // s -> "llo"; s.lshift(8); // s -> ""; 新增shrink()接口,与std::string的shrink_to_fit()类似,用于缩减 fastring 的容量. fastring s(4096); // cap -> 4096 s.shrink(); // cap < 4096 test/unitest 去掉 test/unitest 代码文件名中的_test后缀. 下面附上详细的介绍,以供参考: Basic(English) CO是一个优雅、高效的 C++ 基础库,支持 Linux, Windows 与 Mac 平台。CO追求极简、高效,不依赖于boost等三方库。 CO包含协程库(golang-style)、网络库(tcp/http/rpc)、日志库、命令行与配置文件解析库、单元测试框架、json 库等基本组件。 参考文档 md (中文) md (English) 亮点功能 co co是一个golang风格的 C++ 协程库,有如下特性: 支持多线程调度,默认线程数为系统 CPU 核数. 协程共享线程栈(默认大小为 1MB),内存占用极低,单机可轻松创建数百万协程. 支持系统 api hook (Linux & Mac). 支持协程锁co::Mutex. 支持协程同步事件co::Event. 支持协程池co::Pool. 用go()创建协程: void fun() { std::cout << "hello world" << std::endl; } go(fun); so so是基于协程的 C++ 网络库,可轻松实现同时支持ipv4与ipv6的网络程序,包含如下几个模块: tcp 模块, 支持一般的 tcp 编程. http 模块, 支持基本的 http 编程. rpc 模块,基于 json 的 rpc 框架,单线程 qps 可达到 12w+. 实现静态web server: #include "co/flag.h" #include "co/log.h" #include "co/so.h" DEF_string(d, ".", "root dir"); // 指定 web server 根目录 int main(int argc, char** argv) { flag::init(argc, argv); log::init(); so::easy(FLG_d.c_str()); // mum never have to worry again return 0; } 实现一般的 http server: http::Server serv("0.0.0.0", 80); serv.on_req( [](const http::Req& req, http::Res& res) { if (req.is_method_get()) { if (req.url() == "/hello") { res.set_status(200); res.set_body("hello world"); } else { res.set_status(404); } } else { res.set_status(501); } } ); serv.start(); log log是一个超级快的本地日志系统,打印日志比printf更安全: LOG << "hello " << 23; // info ELOG << "hello again"; // error 下面直观感受一下log的性能: log vs glog google glog co/log win2012 HHD 1.6MB/s 180MB/s win10 SSD 3.7MB/s 560MB/s mac SSD 17MB/s 450MB/s linux SSD 54MB/s 1023MB/s 上表是单线程连续打印 100 万条 info 日志(每条 50 字节左右)的测试结果,co/log几乎快了glog两个数量级。 为何如此快?一是 log 库内部基于比sprintf快 8-25 倍的fastream实现,二是 log 库几乎没有什么内存分配操作。 flag flag是一个方便、易用的命令行及配置文件解析库,支持自动生成配置文件。 #include "co/flag.h" DEF_int32(i, 32, "comments"); DEF_string(s, "xxx", "string type"); int main(int argc, char** argv) { flag::init(argc, argv); std::cout << "i: " << FLG_i << std::endl; std::cout << "s: " << FLG_s << std::endl; return 0; } 编译后运行: ./xx # 以默认参数启动 ./xx -i=4k -s="hello world" # 整数类型可以带单位 k,m,g,t,p, 不分大小写 ./xx -i 4k -s "hello world" # 与上等价 ./xx --mkconf # 自动生成配置文件 xx.conf ./xx -config=xx.conf # 从配置文件启动 json json是一个速度堪比rapidjson的 json 库,如果使用jemalloc,parse与stringify的性能会进一步提升。此库对 json 标准的支持不如 rapidjson 全面,但能满足程序员的基本需求,且更容易使用。 代码构成 co/include libco的头文件。 co/src libco的源代码。 co/test 一些测试代码,每个.cc文件都会编译成一个单独的测试程序。 co/unitest 一些单元测试代码,每个.cc文件对应不同的测试单元,所有代码都会编译到单个测试程序中。 co/gen 代码生成工具,根据 proto 文件,自动生成 rpc 框架代码。 编译执行 xmake CO推荐使用xmake进行编译。 编译器 Linux:gcc 4.8+ Mac:clang 3.3+ Windows:vs2015+ 安装 xmake windows, mac 与 debian/ubuntu 可以直接去 xmake 的release页面下载安装包,其他系统请参考 xmake 的Installation说明。 xmake 在 linux 上默认禁止 root 用户编译,ruki说不安全,可以在~/.bashrc中加上下面的一行,启用 root 编译: export XMAKE_ROOT=y 快速上手 # 所有命令都在 co 根目录执行,后面不再说明 xmake # 默认编译 libco 与 gen xmake -a # 编译所有项目 (libco, gen, co/test, co/unitest) 编译 libco xmake build libco # 编译 libco xmake -b libco # 与上同 编译及运行 unitest 代码 co/unitest是单元测试代码,用于检验 libco 库功能的正确性。 xmake build unitest # build 可以简写为 -b xmake run unitest -a # 执行所有单元测试 xmake r unitest -a # 同上 xmake r unitest -os # 执行单元测试 os xmake r unitest -json # 执行单元测试 json 编译及运行 test 代码 co/test包含了一些测试代码。co/test 目录下增加xxx.cc源文件,然后在 co 根目录下执行xmake build xxx即可构建。 xmake build flag # 编译 flag.cc xmake build log # 编译 log.cc xmake build json # 编译 json.cc xmake build rapidjson # 编译 rapidjson.cc xmake build rpc # 编译 rpc.cc xmake build easy # 编译 so/easy.cc xmake build pingpong # 编译 so/pingpong.cc xmake r flag -xz # 测试 flag 库 xmake r log # 测试 log 库 xmake r log -cout # 终端也打印日志 xmake r log -perf # log 库性能测试 xmake r json # 测试 json xmake r rapidjson # 测试 rapidjson xmake r rpc # 启动 rpc server xmake r rpc -c # 启动 rpc client xmake r easy -d xxx # 启动 web server xmake r pingpong # pingpong server: 127.0.0.1:9988 xmake r pingpong ip=:: # pingpong server: :::9988 (ipv6) xmake r pingpong -c ip=::1 # pingpong client -> ::1:9988 编译 gen # 建议将 gen 放到系统目录下(如 /usr/local/bin/). xmake build gen gen hello_world.proto proto文件格式可以参考hello_world.proto。 安装 # 默认安装头文件、libco、gen xmake install -o pkg # 打包安装到 pkg 目录 xmake i -o pkg # 同上 xmake install -o /usr/local # 安装到 /usr/local 目录 cmake izhengfan帮忙提供了 cmake 支持: 默认只编译libco与gen. 编译生成的库文件在 build/lib 目录下,可执行文件在 build/bin 目录下. 可以用BUILD_ALL指定编译所有项目. 可以用CMAKE_INSTALL_PREFIX指定安装目录. mkdir build && cd build cmake .. cmake .. -DBUILD_ALL=ON -DCMAKE_INSTALL_PREFIX=pkg make -j8 make install License CO以MITLicense 发布.CO包含了一些其他项目的代码,可能使用了与CO不同的 License,详情见LICENSE.md。 特别致谢 co/context的相关代码取自ruki的tbox,特别表示感谢! co 英文参考文档,由Leedehai(1-10),daidai21(11-15) 与google翻译,特别表示感谢! ruki帮忙改进了 xmake 编译脚本,特别表示感谢! izhengfan提供了 cmake 编译脚本,特别表示感谢!

优秀的个人博客,低调大师

搭建hadoop1.2集群

环境准备 我使用的是vmware workstation,首先安装ubuntu 12.04,安装完成后通过vmware的clone,clone出两个虚机,设置的IP分别是: 192.168.74.130 master 192.168.74.132 node1 192.168.74.133 node2 然后修改各个主机的/etc/hosts中的内容。 使用vi或者gedit,将上边的内容编缉进去。 创建用户 先创建hadoop用户组: sudo addgroup hadoop 然后创建用户hadoop: sudo adduser -ingroup hadoop hadoop 注:在centos 和 redhat下直接创建用户就行,会自动生成相关的用户组和相关文件,而ubuntu下直接创建用户,创建的用户没有根目录。 给hadoop用户添加权限,打开/etc/sudoers文件; sudo gedit /etc/sudoers 按回车键后就会打开/etc/sudoers文件了,给hadoop用户赋予root用户同样的权限。 在root ALL=(ALL:ALL) ALL下添加hadoop ALL=(ALL:ALL) ALL, hadoop ALL=(ALL:ALL) ALL 为本机(master)和子节点(node..)安装JDK环境。 其实网上挺多的,参考http://blog.csdn.net/klov001/article/details/8075237,这里不详细描述了。 修改本机(master)和子节点(node..)机器名 打开/etc/hostname文件; sudo gedit /etc/hostname 分别改为master、node1和node2。 本机(master)和子节点(son..)安装ssh服务 主要为ubuntu安装,cents和redhat系统自带。 ubuntu下: sudo apt-get install ssh openssh-server 建立ssh无密码登录环境 做这一步之前首先建议所有的机子全部转换为hadoop用户,以防出现权限问题的干扰。 ssh生成密钥有rsa和dsa两种生成方式,默认情况下采用rsa方式。 创建ssh-key,这里我们采用rsa方式; ssh-keygen -t rsa -P "" (注:回车后会在~/.ssh/下生成两个文件:id_rsa和id_rsa.pub这两个文件是成对出现的) 进入~/.ssh/目录下,将id_rsa.pub追加到authorized_keys授权文件中,开始是没有authorized_keys文件的; cd ~/.ssh cat id_rsa.pub >> authorized_keys 可以使用ssh 主机名测试一下是否成功。 为mater安装hadoop 在hadoop用户下建立hadoop文件夹,然后将hadoop-1.2.0.tar.gz上传到这个目录下。 tar -zxvf hadoop-1.2.0.tar.gz 解压缩。然后到hadoop目录下conf下找到hadoop-env.sh 配置JAVA_HOME为你上面配置的JAVA_HOME。 找到core-site.xml,配置信息如下: <configuration> <property> <name>hadoop.tmp.dir</name> <value>/home/hadoop/tmp/hadoop-${user.name}</value> <description>A base for other temporarydirectories.</description> </property> <property> <name>fs.default.name</name> <value>hdfs://master:9000</value> <description>The name of the default file system. A URI whose scheme and authority determine the FileSystem implementation. The uri's scheme determines the config property (fs.SCHEME.impl) naming the FileSystem implementation class. The uri's authority is used to determine the host, port, etc. for a filesystem. </description> </property> </configuration> 修改hdfs-site.xml: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <!-- Put site-specific property overrides in this file. --> <configuration> <property> <name>dfs.replication</name> <value>2</value> <description>Default block replication. The actual number of replications can be specified when the file iscreated. The default is used if replication is not specified in create time. </description> </property> </configuration> 修改mapred-site.xml: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <!-- Put site-specific property overrides in this file. --> <configuration> <property> <name>mapred.job.tracker</name> <value>master:9001</value> <description>The host and port that the MapReduce job trackerruns at. If "local", then jobs are run in-process as a singlemap and reduce task. </description> </property> </configuration> 修改masters: master 修改slaves: node1 node2 启动hadoop 在master主机上的hadoop安装目录下的bin目录下,执行格式化 ./hadoop namenode -format 正常情况下会出现如下提示: 说明格式化成功。 启动所有结点: ./start-all.sh 会按先后顺序启动,启动完成后,分别到主机和两个node上使用jps查看。 master上显示如下: node1和node2上显示: 在操作的过程中遇到了DataNode不能启动的问题,经过查看node1的hadoop的日志,发现提示错误信息: org.apache.hadoop.hdfs.server.datanode.DataNode: All directories in dfs.data.dir are invalid. 经过查找是因为权限的问题,于是 sudo chmod 755 “你配置的data目录” 问题解决。 运行示例 在根目录下新建文件a,并且向a中随意添加字符串信息。 然后在hdfs上创建目录: ./hadoop dfs -mkdir test1 把刚才创建的文件a上传到test1下: ./hadoop dfs -put ~/a test1 然后查看文件中的内容: ./hadoop dfs -cat test1/a 显示结果如下:

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

用户登录
用户注册