Go pprof 使用

1 概览

pprof 是 Go 提供的一套可视化和分析性能分析数据的工具。 主要包含两部分

  • runtime/pprof 编译进了每个 go 程序

  • go tool pprof 用来分析 profile

Profiling 可以翻译成画像,类似在侦破案件的时候警察会对嫌疑人做的画像。profiling 就是对应用做的画像,描述应用使用 CPU 和内存的情况,用了多少,在哪些地方使用等等。

阅读全文 →

Go 中 JSON 的特殊使用技巧

修改序列化后的 Key 值

 type User struct {
     ID int `json:"id"`
     Name string `json:"name"`
 }

 // output
 {"id": 12, "name": "laily"}

数字转字符串

前端 js 对 int64 的处理可能会因为溢出导致无法准确处理,因此我们期望可以返回字符串类型。

 type User struct {
     ID int64 `json:"id,string"`
 }

 // output
 {"id":"123131"}

忽略零值

 type User struct {
     ID int `json:"id,omitempty"`
     Name string `json:"name,omitempty"`
 }

如果 ID 是 0,Name 是空字符串则在序列化的结果里不会有这两个 key。

阅读全文 →

git 原理

git 原理

数据模型

基本概念

BLOB(binary large object):二进制大对象,是一个可以存储二进制文件的容器。

Untracked:文件刚创建,从未被执行过 git add,在工作区(Working Directory)

阅读全文 →

Nginx 使用

Nginx 使用

配置文件

全局配置部分

user www www;
worker_process 2;

error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid  logs/nginx.pid

events {
  use epoll;
  worker_connections 2048;
}

http {
    ...
    server {
    
    }
}
  • user www www

nginx 的运行用户和组。

  • worker_process 2

再配置文件的顶级 main 部分,表示 worker 角色的工作进程的个数。nginx 进程分为 master 和 worker。master负责接收并分配请求给 worker 处理。这个数值可以简单设置为 cpu 的核数 grep ^processor /proc/cpuinfo | wc -l, 也即是 auto 值。如果开启了 ssl 和 gzip 更应该设置成于逻辑 cpu 数目一样或者 2 倍,可以减少 io 操作。如果 nginx 服务器上还有其他服务,可以适当减少。

阅读全文 →

EOS 节点搭建

EOS 节点搭建

安装 EOS

预编译二进制文件安装

wget https://github.com/EOSIO/eos/releases/download/v1.5.0/eosio_1.5.0-1-ubuntu-16.04_amd64.deb

apt install ./eosio_1.5.0-1-ubuntu-16.04_amd64.deb

这样 eos 的执行文件就在 /usr/opt/eosio/1.5.0/bin/ 目录下。

源码安装

git clone https://github.com/EOSIO/eos --recursive
cd eos
git checkout v1.5.0
git submodule update --init --recursive
./eosio_build.sh

接下来会检查各种依赖包的安装情况,然后询问是否安装缺失依赖,选择 yes。
然后就等待长时间的编译,安装。

阅读全文 →