Skip to content

Instantly share code, notes, and snippets.

View BruceChen7's full-sized avatar
🎯
Focusing

insects BruceChen7

🎯
Focusing
View GitHub Profile
@BruceChen7
BruceChen7 / parca.md
Created August 30, 2023 08:14
#parca

源代码理解

@BruceChen7
BruceChen7 / cli.md
Created February 23, 2023 04:20
#shell#cli#ip

捕获活跃的接口

ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'
@BruceChen7
BruceChen7 / redis.bt
Created December 29, 2022 14:44
#bpftrace#redis
#!/usr/bin/env bpftrace
BEGIN
{
printf("Tracing redis-server function \"getMaxmemoryState\" as inlined into \"performEvictions\".\n");
printf("NOTE: These instrumentation points are from disassembly of the redis-server build:\n");
printf(" SHA1: 25a228b839a93a1395907a03f83e1eee448b0f14\n");
printf(" Build-id: 2fc7c1a80ad026179178fff7045bc7fb4ad3f82d\n");
printf(" Version string: Redis server v=6.2.6 sha=4930d19e:1 malloc=jemalloc-5.1.0 bits=64 build=aa3ee5297f58e2\n");
printf("\n");
@BruceChen7
BruceChen7 / pointer.go
Created December 13, 2022 14:54
#golang#pointer
func (p *page) meta() *meta {
return (*meta)(unsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p)))
}
func unsafeAdd(base unsafe.Pointer, offset uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(base) + offset)
}
@BruceChen7
BruceChen7 / video.md
Created November 18, 2022 08:14
#video

什么是分辨率

不同的分辨率之间具体有什么区别呢?我们下面就以 720p、1080p 为例进行说明。

  • 我们常说的 1080 和 720 其实是指垂直像素数,分辨率除去垂直像素,还需要考虑到水平像素数。
  • 按照 16:9 (宽 : 高) 的比例计算,720p 的水平像素数为 720 ÷ 9 × 16 = 1280,
  • 总计像素为921600像素即大约为 92 万像素。

1080p 具有 1920 个水平像素,总计2073600像素即约 200 万像素,是 720p 的两倍多。 而像素越多视频就越清晰,所以 1080p 比 720p 的视频更加清晰。

@BruceChen7
BruceChen7 / macd.md
Last active May 19, 2024 07:38
#MACD#

链接

什么是MACD

MACD指标由一组曲线与图形组成,通过收盘时股价或指数的快变及慢变的指数移动平均值(EMA)之间的差计算出来。快”指更短时段的EMA,而“慢”则指较长时段的EMA,最常用的是12日及26日的EMA。

  • 棒形图会根据正负值分布在零轴(X轴)的上下。棒形图在零轴上方时表示走势较强(牛市),反之则是走势较弱(熊市)。
  • 差离值由下而上穿过零轴代表市场气氛利好股价,相反由上而下则代表利淡股价。差离值与讯号线均在零轴上方时,被称为多头市场,反之,则被称为空头市场。

image

@BruceChen7
BruceChen7 / emacs.md
Last active October 23, 2022 17:17
#emacs

移动

  • C-v 移动到下一屏幕
  • M-V 移动到上一屏幕
  • C-b 移动上一个字符
  • C-f 移动到一个字符
  • C-p 移动到上一个行
  • C-n 移动到下一行
  • M-f 移动到单词的后面
  • M-b 移动到单词前面
  • M-a 移动到一个句子前面
@BruceChen7
BruceChen7 / latency.md
Last active August 18, 2022 17:30
#latency#throughput

基本概念

Latency,中文译作延迟。Throughput,中文译作吞吐量。它们是衡量软件系统的最常见的两个指标。延迟一般包括单向延迟(One-way Latency)和往返延迟(Round Trip Latency),实际测量时一般取往返延迟。它的单位一般是ms、s、min、h等。 而吞吐量一般指相当一段时间内测量出来的系统单位时间处理的任务数或事务数(TPS)。注意“相当一段时间”,不是几秒,而可能是十几分钟、半个小时、一天、几周甚至几月。它的单位一般是TPS、每单位时间写入磁盘的字节数等。

低延迟一定意味着高吞吐量吗?如果不是,试举出反例。假如有一个网站系统,客户端每次请求网站服务端,网络传输时间(包括往返)为 200ms,服务端处理请求为10ms。那么如果是同步请求,则延迟为210ms。此时如果提高网络传输速度,比如提高到100ms,那么延迟为110ms。这种情况减少延迟似乎确实可以一定程度提高吞吐量,原因主要在于:系统性能瓶颈不在于服务端处理速度,而在于网络传输速度。 继续假设将同步请求改为异步请求,那么现在延迟为100ms,延迟降低了,但吞吐量保持不变。所以这是一个反例。

除了上面这个反例外,还有一个更生动的反例:火车、飞机运煤:从山西到广州运煤,一列火车100小时(包括往返)可以运输10000t煤,而一架飞机20小时(包括往返)可以运输100t煤,显然飞机运煤的延迟明显低于火车运煤,但如果测试运10000t煤,则火车运煤的吞吐量远高于飞机

火车运煤的吞吐量为100t/小时,飞机运煤的吞吐量为5t/小时,我们可以将上面的运煤场景类比软件系统,火车、飞机运煤可以比作Web服务器处理请求,比如Apache和Nginx。在并发请求数不高时,比如10000(我假设的)以下时,也许Apache的吞吐量可能优于Nginx,但在大于10000时Apache的吞吐量就开始急剧下降,而Nginx的吞吐量相对之前比较稳定。所以比较Web服务器的吞吐量时,必须观察在并发请求数逐渐递增情况下它们各自的表现。根据延迟和吞吐量我们还可以计算并发度(Concurrency),公式如下:

@BruceChen7
BruceChen7 / dot-repeating.md
Created August 16, 2022 13:26 — forked from kylechui/dot-repeating.md
A basic overview of how to manage dot-repeating in your Neovim plugin, as well as manipulate it to "force" what action is repeated.

Adding dot-repeat to your Neovim plugin

In Neovim, the . character repeats "the most recent action"; however, this is not always respected by plugin actions. Here we will explore how to build dot-repeat support directly into your plugin, bypassing the requirement of dependencies like repeat.vim.

The Basics

When some buffer-modifying action is performed, Neovim implicitly remembers the operator (e.g. d), motion (e.g. iw), and some other miscellaneous information. When the dot-repeat command is called, Neovim repeats that operator-motion combination. For example, if we type ci"text<Esc>, then we replace the inner contents of some double quotes with text, i.e. "hello world""text". Dot-repeating from here will do the same, i.e. "more samples""text".

Using operatorfunc

@BruceChen7
BruceChen7 / raft.go
Created August 12, 2022 16:22
#golang#raft#leader#network
func (r *Raft) requestVote(rpc RPC, req *RequestVoteRequest) {
defer metrics.MeasureSince([]string{"raft", "rpc", "requestVote"}, time.Now())
r.observe(*req)
// Setup a response
resp := &RequestVoteResponse{
RPCHeader: r.getRPCHeader(),
// 返回自己节点的任期
Term: r.getCurrentTerm(),
Granted: false,