Protocol Buffer Syntax and Encoding

Protocol Buffer Syntax and Encoding Principles [toc] Serialization refers to the process of converting structured data into a format that is easy to store or transmit. Protocol Buffer, abbreviated as ProtoBuf, is a language- and platform-independent serialization tool developed by Google and open-sourced in 2008. Compared to commonly used serialization tools such as XML, JSON, YAML, and CSV, ProtoBuf has advantages including smaller serialized data size, faster serialization and deserialization, lower maintenance cost through the use of proto files, and backward compatibility....

April 5, 2023 · 14 min

Redis 持久化机制: RDB 和 AOF

Redis 持久化机制: RDB 和 AOF Redis 持久化 为什么需要持久化? Redis 是基于内存的数据库, 服务一旦宕机, 内存中的数据将全部丢失. 通常来说可以通过数据库来恢复这些数据, 但这会给数据库带来非常大的读压力, 并且这个过程会非常缓慢, 并导致程序响应慢, 因此 Redis 提供了把内存数据持久化到硬盘, 并通过备份文件来恢复数据的功能, 即持久化机制. 持久化的方式 目前 Redis Documentation 上对持久化的支持有以下几种方案: RDB (Redis Database): 将某个时间点上的数据生成快照 (snapshot) 并保存到硬盘上 AOF (Append Only File): 将每个接收到的写操作记录到硬盘上, 这些操作可以在 Redis 重启时被重放, 并用于重新构建 Redis 数据库 RDB + AOF: AOF 和 RDB 的混合模式 RDB RDB 指对整个数据集在特定时间点生成快照 (point-to-time snapshot), 可用于Redis的数据备份, 转移和恢复. 它是 Redis 默认使用的持久化方案. 工作原理 RDB 利用操作系统提供的写时复制 (Copy-on-Write) 机制来进行持久化, 即当主进程 P fork 出子进程时 Q 时, Q 和 P 共享同一块内存空间, 当 P 准备对某块内存进行写操作时, P 会将这块内存页进行复制, 并在新的副本上对数据进行修改, 而 Q 仍然读取原先的内存页....

February 1, 2023 · 3 min

Disaster Recovery Architecture on AWS

Disaster Recovery Architecture on AWS [TOC] The downtime of software systems could have a significant impact on business, customer satisfaction, reputation, or income of the company. Thus maintaining the availability and durability must be the most crucial part of a software system. Disaster recovery (DR) helps engineers prepare for disaster events. This post summaries the architecture for DR on AWS. DR objectives There are two key objectives: Recovery time objective (RTO): The maximum time range between service collapse and service restoration....

January 11, 2023 · 4 min

Git Reference

Git Reference HEAD 用法 HEAD 最后一次 commit HEAD^ 倒数第二次 commit HEAD^^ 倒数第三次 commit,以此类推 HEAD~0 最后一次 commit HEAD~1 倒数第二次 commit HEAD^2 倒数第三次 commit,以此类推 回到以前的某次 commit git reflog # Reference logs 记录了本地仓库每一次更新分支的操作 git reset HEAD@{index} # 回到某一次提交,把文件修改留在工作区 git reset hash --hard # 加上 --hard 可以忽略掉所有文件修改 在最后一次 commit 的基础上添加部分改动 git add . # 把改动添加到暂存区 git commit --amend # git commit --amend --no-edit # 加上 --no-edit 如果最后一次 commit 已经 push 到 remote,那么在再次 push 的时候需要加上 -f...

March 31, 2022 · 2 min

使用 Mac Mini M1 作为软路由让全家设备科学上网

使用 Mac Mini M1 作为软路由让全家设备出国 [TOC] 本文介绍如何将功耗超低的 Mac Mini M1 改造为软路由,让局域网内连上 Wi-Fi 的所有家庭设备都可以免设置直接出国。 代理客户端 首先需要下载一个可以运行在 M1 上的代理客户端,推荐使用 Surge 或者 ClashX Pro,前者买断价格较贵(每个 Mac 设备 $49.99),后者免费,本文以后者为例。 配置 一般机场会提供 Clash 的订阅链接,如果没有可以自行搜索 ssr/v2ray 转 clash 的第三方订阅转换服务,生成 Clash 订阅链接。 有了订阅链接之后,点击顶部菜单栏的 Clash 图标 -> Config -> Remote config -> Manage 管理订阅。 点击 Add,在 Url 中输入订阅链接,Config Name 可以任意填。 除此之外还要勾选 Clash 图标里的 Set as system proxy 和 Enhanced Mode 两个选项,这样才能保证 Mac Mini M1 能够成为网关。 设置网关 到此 Mac Mini M1 已经可以成功地出国了,现在将 Mac Mini M1 作为网管,对路由器上的所有流量进行代理。...

February 27, 2022 · 1 min