`
tcspecial
  • 浏览: 894878 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论
文章列表
  有时需要扩展公共模块的功能,各个子模块实现各自业务逻辑,protobuf 提供了extensions用于处理该场景。   公共协议comm_info.proto package test; message CommReq { optional int id = 1; extensions 10000 to 12000; // 预留[10000,12000]用于扩展 }    业务模块user_info.proto import "pb/comm_info.proto"; package test; message User ...
  最近线上遇到一个问题,python定时任务运行到一半时就因为OOM被kill退出。 程序主要是利用MySQLdb插件导出db流水数据,流水数据比较大,有430w条记录,因此分多次加载数据。 db = MySQLdb.connect(host, user, pwd, db, port) curs = db.cursor() # 由于数据较大,不能通过fetchall()一次性读取 rec = curs.fetchone() while rec: print rec rec = curs.fetchone()    但是做了上述优化后,脚本仍然会因为OOM被kil ...
  fdate按日期分区 create table myevent ( fdate int(11) not null default '0', appid int, primary key(fdate) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION BY RANGE(TO_DAYS(fdate)) (PARTITION p20190217 VALUES LESS THAN (TO_DAYS('2019-02-17')) ENGINE = InnoDB, PARTITION p20190218 VALUES LESS T ...
  现在很多python模块不支持python2了,迁移至python3是大势所趋。 操作系统版本: Linux 3.10.107   1. 安装python3.7.2 下载源码编译安装后,发现目录下未生成pip,手动安装: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py   运行报错:   ModuleNotFoundError: No module named '_ctypes'     ctypes是python与c混合编程库,安装ffi 组件:   s ...
  一. std::move c++11 提供了move语义,可以实现资源转移,提高系统性能。   源码实现: /** * @brief Convert a value to an rvalue. * @param __t A thing of arbitrary type. * @return The parameter cast to an rvalue-reference to allow moving it. */ template<typename _Tp> constexpr typename std::remove_refer ...

c++11 chrono

  chrono是c++11中的时间库,提供了大量操作时间的API。 程序睡眠: std::this_thread::sleep_for( std::chrono::seconds(10) );   上述代码过于繁琐,可简化: using namespace std::chrono_literals; std::this_thread::sleep_for(10s);    实现源码: constexpr std::chrono::seconds operator ""s(unsigned long long s) { return std ...
  一. 模板全特化 有时当通用模板无法处理特定类型,需要对模板参数进行特殊处理,即为特化。 // 通用模板 template<class T> struct A { int x; }; // 特化T=double,模板为空 template<> struct A<double> { int y; };     模板偏特化,即对模板部分参数进行特化。 // 通用模板 template<class T, class P> void foo(T t, P p){} // 偏特化,第二个 ...
  很多开源代码在makefile中会使用pkg-config,pkg-config是linux下获取系统库/模块信息的命令。   一. 用法 $ pkg-config --libs --cflags grpc -I/usr/local/include -L/usr/local/lib -lgrpc  查看grpc头文件路径及依赖库名称。   $ pkg-config --list-all grpc++_unsecure gRPC++ unsecure - C++ wrapper for gRPC without SSL libidn2 libidn2 - ...

nginx 接入gRPC

  nginx 1.13.10新增了对gRPC的支持,本文介绍通过nginx接入grpc服务。   一. nginx版本 $ nginx -V nginx version: nginx/1.15.6 built by clang 10.0.0 (clang-1000.11.45.5) built with OpenSSL 1.0.2p 14 Aug 2018 TLS SNI support enabled --with-http_ssl_module --with-http_v2_module  若源码安装,需指定http2编译选项:--with-http_v2_mod ...

gRPC C++

  一. 准备编译环境 安装各种依赖库,详见:Pre-requisites brew install autoconf automake libtool shtool gflags   二. 安装protobuf3 git clone https://github.com/google/protobuf.git cd protobuf git checkout v3.5.0 sh ./autogen.sh ./configure --prefix=/usr/local/protobuf ...
  protobuf 提供了反射API,可以很方便操作pb字段。 // 遍历pb字段 bool ParsePb(google::protobuf::Message *oReq, std::map<std::string, std::string> &vParams) { // Descriptor: message类型定义描述 const google::protobuf::Descriptor *descriptor = oReq->GetDescriptor(); // Reflection: 动态读写pb字段 c ...
      addr2line 命令可以在程序core时,提供一种辅助手段定位程序问题。      下面演示除零错误: #include <stdio.h> int main(int argc, char **argv) { int x = 10; int y = 0; printf("%d/%d=%d\n", x, y, x/y); return 0; }       程序执行后立即退出,可查看系统dmesg日志: $ ./test Floating point exception (core dumped) $ ...

tcp 粘包

由于tcp流式传输,受限于缓冲区大小,会导致一个数据包分多个发送情况。应用程序需处理该边界。 粘包常见的处理方式有以下三种:   1. 结束符方式 std::string readLine(void) { char *pos; while (!(_buffer.size()) || !(pos = strchr(_buffer.data(), '\n'))) { if (readData(_buffer, 4096) <= 0) { pos = _buffer.data() + _bu ...
  1. decay std::decay对类型进行退化处理。 a. T为数组U或数组U引用,则type为U*. b. T为函数时,则type为std::add_pointer<F>::type. c. 其它类型则移除cv限定符(const和volatile),则type为std::remove_cv<std::remove_reference<T>::type>::type. decay_equiv<const int&, int>::value // true decay_equiv<int[2], int*&g ...
C++ 没有类似Java反射机制,无法动态获取对象元信息,那么如何检测对象是否存在成员函数呢?   1. 检测是否存在特定成员函数 muduo框架中有这样一段代码: vi muduo/base/Singleton.h template<typename T> struct has_no_destroy { template <typename C> static char test(decltype(&C::no_destroy)); // 返回char template <typename C> st ...
Global site tag (gtag.js) - Google Analytics