202208

postgree

How to copy with statement result to local in postgresql
https://stackoverflow.com/questions/64438775/how-to-copy-with-statement-result-to-local-in-postgresql

create temporary view data_to_export
as
with cte as (..)
select *
from cte
;

\copy (select * data_to_export) to ...

Postgres: return first N rows per group for groups having a minimum countI
https://stackoverflow.com/questions/38589305/postgres-return-first-n-rows-per-group-for-groups-having-a-minimum-counti

SELECT userid, createdat, displaydate
FROM (SELECT t.*,
             ROW_NUMBER() OVER (PARTITION BY userid ORDER BY createdat) as seqnum,
             COUNT(*) OVER (PARTITION BY userid) as cnt
      FROM data t
     ) x
WHERE x.seqnum <= 100 AND x.cnt > 100;

PostgreSQL操作JSON数据
https://blog.csdn.net/qq_42715450/article/details/121350279

 // -> 返回json
 select '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json->2 // 输出 {"c":"baz"}
 select '{"a": {"b":"foo"}, "c":{"a": "aaa"}}'::json->'a' // 输出 {"b":"foo"}

 // ->> 返回文本
 select '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json->>2 // 输出 {"c":"baz"}
 select '{"a": {"b":"foo"}, "c":{"a": "aaa"}}'::json->>'a' // 输出 {"b":"foo"}

 // #> 获取json子对象
 select '{"a": {"b":{"c": "foo"}}}'::json#> '{a,b}' // 输出 {"c": "foo"}
 select '{"a": {"b":{"c": "foo"}}}'::json#>> '{a,b}' // 输出 {"c": "foo"}

 // @> ———— 判断第一个json是否包含第二个
 select '{"a":1, "b":2}'::jsonb @> '{"b":2}'::jsonb   //输出t
 // <@ ———— 判断第一个json是否在第一个中
 select '{"b":2}'::jsonb <@ '{"a":1, "b":2}'::jsonb   //输出t

PostgreSQL 安装
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-20-04

sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql.service
sudo -i -u postgres
psql

sudo -u postgres createuser --interactive
    mydb 
sudo -u postgres createdb mydb 
sudo adduser mydb 
sudo -u mydb psql
    \conninfo
    create schema mydb 
grep -n CREATE 1.sql
sed -n '1147637,1148637p' 1.sql  > 5.sql
sudo -u mydb psql -d mydb -U mydb -f 5.sql

PostgreSQL查询当前执行中SQL的执行计划——pg_show_plans
https://www.cnblogs.com/lovezhr/p/15180691.html

  • 通常情况,我们可以通过explain、explain analyze、explain verbose来获取执行计划。
  • 但是explain查询当前缓存的执行计划,在实际中估算的成本可能是不准确的,因为很可能估算的成本和实际运行的成本不一致。而explain analyze、explain verbose则会实际执行SQL,但在某些场景不会被允许执行。
  • 可以尝试采用开启一个事务后,explain analyze、explain verbose查看执行计划,最后rollback。
  • pg_show_plans是一个显示当前运行的所有SQL语句执行计划的模块。

AI

小波变换和傅里叶变换
https://blog.csdn.net/qq_43528044/article/details/121533574

  • 要讲小波变换,我们必须了解傅立叶变换。要了解傅立叶变换,我们先要弄清楚什么是”变换“。
  • 很多处理,不管是压缩也好,滤波也好,图形处理也好,本质都是变换。变换的是什么东西呢?是基,也就是basis。
  • 简单说,在线性代数里,basis 是指空间里一系列线性独立的向量,而这个空间里的任何其他向量,都可以由这些个向量的线性组合来表示。
  • 小波指的是一种能量在时域非常集中的波,它的能量有限,都集中在某一点附近,而且积分的值为零,这说明它与傅里叶波一样是正交波。

MediaPipe介绍
https://blog.csdn.net/weixin_38346042/article/details/123399492

  • MediaPipe为我们日常使用的革命性产品和服务提供动力。与资源消耗型的机器学习框架不同,MediaPipe只需要最少的资源。
  • MediaPipe是一个用于构建机器学习管道的框架,用于处理视频、音频等时间序列数据。
  • Solutions是基于特定的预训练TensorFlow或TFLite模型的开源预构建示例:
    • 人脸检测
    • Face Mesh
    • 虹膜
    • 手势
    • 姿态
    • 人体
    • 人物分割
    • 头发分割
    • 目标检测
    • Box Tracking
    • Instant Motion Tracking
    • 3D目标检测
    • 特征匹配
    • AutoFlip
    • MediaSequence
    • YouTube-8M
  • MediaPipe依赖OpenCV来处理视频,FFMPEG来处理音频数据。它还有其他依赖项,如OpenGL/Metal、Tensorflow、Eigen等。

javascript 函数时

实现分组聚合

> var group_by_count = list => list.reduce((a, b) => (a[b] = a[b] ? a[b]+1 : 1,a) , {})
undefined
> group_by_count([1,2,3,2,2,3])
{ '1': 1, '2': 3, '3': 2 }
> group_by_count('aabbbcc'.split(''))
{ a: 2, b: 3, c: 2 }
> var by_fun = x => x
undefined
> by_fun(5)
5
> var sum = list => list.reduce((r, x) => r+x, 0)
undefined
> sum([1,2,3])
6
> var avg = list => sum(list)/list.length
undefined
> avg([1,2,3])
2
> var group_by = (list, by) => list.reduce((r, x) => (k = by(x),r[k]||(r[k]=[]),r[k].push(x),r), {})
undefined
> groups = group_by([1,2,3,2,2,3], x=>x)
{ '1': [ 1 ], '2': [ 2, 2, 2 ], '3': [ 3, 3 ] }
> var agg = (groups, fun) => Object.entries(groups).reduce((r, x) => (r[x[0]]=fun(x[1]),r), {})
undefined
> agg(groups, sum)
{ '1': 1, '2': 6, '3': 6 }
> by_a = x=>x['a']
[Function: by_a]
> sum_b = x=>sum(x.map(y=>y['b']))
[Function: sum_b]
> var group_agg = (list, by_fun, agg_fun) => agg(group_by(list, by_fun), agg_fun)
undefined
> group_agg([{a:1,b:2},{a:1,b:2},{a:2,b:3}], by_a, sum_b)
{ '1': 4, '2': 3 }

Laravel

Schedule

$schedule->call(function () {
    Log::info('任务调度');
})->everyMinute();
->cron(‘* * * * *’); 在自定义Cron调度上运行任务

->everyMinute(); 每分钟运行一次任务
->everyFiveMinutes(); 每五分钟运行一次任务
->everyTenMinutes(); 每十分钟运行一次任务
->everyThirtyMinutes(); 每三十分钟运行一次任务
->hourly(); 每小时运行一次任务
->daily(); 每天凌晨零点运行任务
->dailyAt(‘13:00’); 每天13:00运行任务
->twiceDaily(1, 13); 每天1:00 & 13:00运行任务
->weekly(); 每周运行一次任务
->monthly(); 每月运行一次任务

C 语言

请SSE/SSE2熟悉的前辈指点下指令,比较简单
https://bbs.csdn.net/topics/391003443

  • src/des 地址十六字节对齐
  • 复制数据量 大于 512 bytes

标准库的 memcpy 在满足这两个条件的情况下 会使用 sse 的 movdqa 来复制

TLB缓存是个神马鬼,如何查看TLB miss?
https://zhuanlan.zhihu.com/p/79607142

perf stat -e dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses

How to increase performance of memcpy
https://stackoverflow.com/questions/4260602/how-to-increase-performance-of-memcpy

you should have SSE or similar extensions enabled as the vector unit often can write 128 bits to the memory compared to 64 bits for the CPU. and make sure that both the source and destination is aligned to 128 bits. If your source and destination are not aligned respective to each other your memcpy() will have to do some serious magic. :)

First of all, you need to check that memory is aligned on 16 byte boundary, otherwise you get penalties. This is the most important thing.

rep movsb指令解析
movsb指令用于把字节从ds:si 搬到es:di;rep是repeat的意思,rep movsb 就是多次搬运。搬运前先把字符串的长度存在cx寄存器中,然后重复的次数就是cx寄存器所存数据的值。

gcc 内联asm
https://blog.csdn.net/farmwang/article/details/50153529

#include <stdio.h>  
  
int main()  
{  
    int a=1, b=2, c=0;  
  
    // 蛋疼的 add 操作  
    asm(  
        "addl %2, %0"       // 1  
        : "=g"(c)           // 2  
        : "0"(a), "g"(b)    // 3  
        : "memory");        // 4  
  
    printf("现在c是:%d\n", c);  
    return 0;  
}  

软件架构设计 专栏
https://www.zhihu.com/column/kls-software-arch-world

弟子规:美国军方禁止在C语言程序中使用malloc
https://zhuanlan.zhihu.com/p/69365944

多核MMU和ASID管理逻辑
https://zhuanlan.zhihu.com/p/118244515

false sharing(伪共享) 及 c代码实现
https://zhuanlan.zhihu.com/p/417325161

MESI协议将cache line的状态分成以下四种:

  • Modified:当前CPU cache拥有最新数据,被修改过的(最新的cache line),其他CPU拥有失效数据(cache line的状态是Invalid),当被写回主存之后,该缓存行的状态会变成Exclusive状态,其他CPU必须在下次需要时从主存读取数据;
  • Exclusive:只有当前CPU中有数据,其他CPU中没有改数据,当前CPU的数据和主存中的数据是一致的,当有其他CPU读取该缓存行时,变为Shared;
  • Shared:当前CPU和其他CPU中都有共同数据,并且和主存中的数据一致,当一个CPU修改该缓存行时,其他CPU对应的缓存行数据变为Modified;
  • Invalid:当前CPU中的数据失效,数据应该从主存中获取,其他CPU中可能有数据也可能无数据,当前CPU中的数据和主存被认为是不一致的;

memcpy() implementation
https://codereview.stackexchange.com/questions/41094/memcpy-implementation

Very fast memcpy for image processing?
https://stackoverflow.com/questions/1715224/very-fast-memcpy-for-image-processing/1715385#1715385

implicit declaration of function ‘gets’; did you mean ‘fgets’?
c11下去除了gets函数,我们可以用fgets函数来代替。

Address Sanitizer 用法 asan
https://www.jianshu.com/p/3a2df9b7c353

Implementing realloc in C
https://codereview.stackexchange.com/questions/151019/implementing-realloc-in-c

munmap_chunk(): invalid pointer
https://stackoverflow.com/questions/32118545/munmap-chunk-invalid-pointer

realloc() invalid old size
https://stackoverflow.com/questions/24579698/realloc-invalid-old-size

appending to a memory-mapped file
https://stackoverflow.com/questions/4460507/appending-to-a-memory-mapped-file

void *new_mapping = mremap(mapping, size, size + GROWTH, MREMAP_MAYMOVE);
if (new_mapping == MAP_FAILED)
    // handle error
mapping = new_mapping;

How to get mmap’ed memory to sync to the file?
https://stackoverflow.com/questions/16032396/how-to-get-mmaped-memory-to-sync-to-the-file

Also, you need to set the size of the file with ftruncate. Otherwise the mmaped area just covers parts of the file that don’t exist.

If you really want to make sure that the data ends up on disk, use msync, but normally you’ll be able to see the contents you wrote into the mmap:ed area immediately unless you’re on one of the few operating systems that doesn’t have a unified buffer and object cache.

Linux内存映射
https://blog.csdn.net/qq_43334597/article/details/124306981

按文件分:

  • 文件映射:将一个文件的一部分直接映射到调用进程的虚拟内存中
  • 匿名映射:没有对应文件,被映射的分页会初始化为0

按权限分:

  • 私有映射:写时复制,变更不会再底层文件进行
  • 共享映射:变更发生在底层文件

将上面两两组合:

  • 私有文件映射:使用一个文件的内容来初始化一块内存区域
  • 私有匿名映射:为一个进程分配新的内存
  • 共享文件映射:代替 read() 和 write() 、IPC
  • 共享匿名映射:实现相关进程实现类似于共享内存

进程执行 exec() 时映射会丢失,但通过 fork() 的子进程会继承映射

qsort doesn’t sort negative floats correctly
https://github.com/emscripten-core/emscripten/issues/4204

用库函数 qsort 对 float 数组进行排序的时候有 bug,不能写成

return *(float*)a-*(float*)b

因为qsort对负的浮点数支持有问题,得写成

if (a>b) return 1;
if (a<b) return -1;
return 0;

随机浮点数: https://stackoverflow.com/questions/13408990/how-to-generate-random-float-number-in-c

float float_rand( float min, float max )
{
    float scale = rand() / (float) RAND_MAX; /* [0, 1.0] */
    return min + scale * ( max - min );      /* [min, max] */
}

How do realloc and memcpy work?
https://stackoverflow.com/questions/362760/how-do-realloc-and-memcpy-work

The performance of memcpy can’t really be better than O(N) but it can be optimized so that it outperforms manual copying; for example, it might be able to copy 4 bytes in the time it takes you to copy 1 byte. Many memcpy implementations are written in assembly using optimized instructions that can copy multiple elements at a time which is usually faster than copying data one byte at a time.

C - split string into an array of strings
https://stackoverflow.com/questions/11198604/c-split-string-into-an-array-of-strings

char    str[]= "ls -l";
char ** res  = NULL;
char *  p    = strtok (str, " ");
int n_spaces = 0, i;


/* split string and append tokens to 'res' */
while (p) {
  res = realloc (res, sizeof (char*) * ++n_spaces);
  if (res == NULL)
    exit (-1); /* memory allocation failed */
  res[n_spaces-1] = p;
  p = strtok (NULL, " ");
}

/* realloc one extra element for the last NULL */
res = realloc (res, sizeof (char*) * (n_spaces+1));
res[n_spaces] = 0;

/* print the result */
for (i = 0; i < (n_spaces+1); ++i)
  printf ("res[%d] = %s\n", i, res[i]);

/* free the memory allocated */
free (res);

Removing trailing newline character from fgets() input
https://stackoverflow.com/questions/2693776/removing-trailing-newline-character-from-fgets-input

buffer[strcspn(buffer, "\n")] = 0;
buffer[strcspn(buffer, "\r\n")] = 0; // works for LF, CR, CRLF, LFCR, ...

line[strlen(line) - 1] = '\0';

char buffer[100];
if (fgets(buffer, sizeof buffer, stdin) != NULL) {
    size_t len = strlen(buffer);
    if (len > 0 && buffer[len-1] == '\n') {
        buffer[--len] = '\0';
    }
}

Trim a string in C [duplicate]
https://stackoverflow.com/questions/656542/trim-a-string-in-c

char *ltrim(char *s)
{
    while(isspace(*s)) s++;
    return s;
}

char *rtrim(char *s)
{
    char* back = s + strlen(s);
    while(isspace(*--back));
    *(back+1) = '\0';
    return s;
}

char *trim(char *s)
{
    return rtrim(ltrim(s));
}

// Note: This function returns a pointer to a substring of the original string.
// If the given string was allocated dynamically, the caller must not overwrite
// that pointer with the returned value, since the original pointer must be
// deallocated using the same allocator with which it was allocated.  The return
// value must NOT be deallocated using free() etc.
char *trimwhitespace(char *str)
{
  char *end;

  // Trim leading space
  while(isspace((unsigned char)*str)) str++;

  if(*str == 0)  // All spaces?
    return str;

  // Trim trailing space
  end = str + strlen(str) - 1;
  while(end > str && isspace((unsigned char)*end)) end--;

  // Write new null terminator character
  end[1] = '\0';

  return str;
}

C read file line by line
https://stackoverflow.com/questions/3501338/c-read-file-line-by-line

#define _GNU_SOURCE

FILE * fp;
char * line = NULL;
size_t len = 0;
ssize_t read;
while ((read = getline(&line, &len, fp)) != -1) {
    printf("Retrieved line of length %zu:\n", read);
    printf("%s", line);
}
if (line) free(line);

python

基于pywebview的桌面小工具开发记录
https://www.jianshu.com/p/3909e8b90c22

史上最全面K近邻算法/KNN算法详解+python实现
https://zhuanlan.zhihu.com/p/341572059

def euc_dis(instance1, instance2):
    return np.sqrt(np.sum((instance1-instance2)**2))

def knn_classify(X, y, testInstance, k):
    dists=[euc_dis(x,testInstance) for x in X]
    idxknn= np.argsort(dists)[:k]
    yknn=y[idxknn]
    return Counter(yknn).most_common(1)[0][0]

predictions = [knn_classify(X_train, y_train, data, 3) for data in X_test]
correct = np.count_nonzero((predictions==y_test)==True)
print ("Accuracy is: %.3f" %(correct/len(X_test)))

如果选择较大K值,就相当于用较大邻域中的训练实例进行预测,其优点是可以减少学习的估计误差,但近似误差会增大,也就是对输入实例预测不准确,K值得增大就意味着整体模型变的简单

  • 近似误差:**可以理解为对现有训练集的训练误差。
  • 估计误差:**可以理解为对测试集的测试误差。
  • 近似误差关注训练集,如果k值小了会出现过拟合的现象,对现有的训练集能有很好的预测,但是对未知的测试样本将会出现较大偏差的预测。模型本身不是最接近最佳模型。
  • 估计误差关注测试集,估计误差小了说明对未知数据的预测能力好。模型本身最接近最佳模型。

鸢尾花(Iris)数据集
https://blog.csdn.net/qinzhongyuan/article/details/106434854

算法

史上最强图解Treap总结, 不是浅谈!
https://blog.csdn.net/simpsonk/article/details/72832959

树堆(Treap)图文详解与实现
https://cloud.tencent.com/developer/article/1177129

面试官问我:什么是树堆(Treap)?
https://zhuanlan.zhihu.com/p/375122996

gdb

gcc -g 051.c
gdb ./a.out
    r

javascript

使用 Service Workers
https://developer.mozilla.org/zh-CN/docs/Web/API/Service_Worker_API/Using_Service_Workers

The difference between Service Workers, Web Workers and WebSockets
https://aarontgrogg.com/blog/2015/07/20/the-difference-between-service-workers-web-workers-and-websockets/

linux

聊聊CPU的LOCK指令
https://mp.weixin.qq.com/s/8A4sas51tqMmpOwa7pCnJg

计算机组成-无锁编程追求极致性能
https://zhuanlan.zhihu.com/p/330476321

Cache和DMA一致性
https://zhuanlan.zhihu.com/p/109919756

并发基础理论:缓存可见性、MESI协议、内存屏障、JMM
https://zhuanlan.zhihu.com/p/84500221

单片机入门之锁存器
https://baijiahao.baidu.com/s?id=1725115907776029134&wfr=spider&for=pc

  • 数字系统中,要经常用到能存储二进制信息(数字信息)的电路,而锁存器就具有这种功能。
  • 双稳态电路的特点是具有两个稳定的状态,并且在外加触发信号的作用下,可以由一种稳定状态转换为另一种稳定状态。
  • 锁存器基本特性:
    • 它有两个稳定状态,可分别用来表示二进制数0和1;
    • 在输入信号作用下锁存器的两个稳定状态可相互转换,输入信号消失后,已转换的稳定状态可长期保持(在通电状态下)。
  • RS锁存器可以由两个与非门,或者两个或非门实现。
  • 与非门的逻辑特点:全1输出0,有0输出1

特殊用途寄存器,顾名思义是仅为一项任务而设计的寄存器。例如,cs,ds,gs 和其他段寄存器属于特殊目的寄存器,因为它们的存在是为了保存段号。 eax,ecx 等是一般用途的寄存器,因为你可以无限制地使用它们。 例如,你不能移动 ds,但是可以移动 eax,ebx。

  • 通用目的寄存器比如有:eax、ecx、edx、ebx、esi、edi、ebp、esp
  • 特殊目的寄存器比如有:cs、ds、ss、es、fs、gs、eip、flag

分享一些eBPF技术相关的PDF
https://www.cnxct.com/ebpf-slide-pdf-share/
https://github.com/ehids/ebpf-slide

linux下直接I/O(direct io)深入解析与实践
http://t.zoukankan.com/zhjh256-p-12182523.html

  • 默认情况下,linux会将进程未使用的内存用于页面缓存,因为相比直接读写磁盘而言,内存的性能高几个数量级,即使是SSD亦如此。
  • 虽然页面缓存能够极大的提升性能,但是其不是没有缺点的,尤其是哪些只会读写一次或应用自身对数据进行了缓存的应用如oracle/mysql,如果全部os缓存,很可能会导致应用内存不足(特别是在应用不支持启动时lock memory或多应用环境下无法这么做时)。
  • 如果没有缓存,随机直接(指的是4K/8K块)I/O的性能是非常低下的。大块(顺序I/O)则快得多。
    • echo 1 > /proc/sys/vm/drop_caches 清空缓存
    • dd if=/dev/zero of=./a.dat bs=4k count=1M oflag=direct 小块io
    • dd if=/dev/zero of=./a.dat bs=1M count=4K oflag=direct 大块 io
    • sar -r 3 1000 监控内存变化
  • nocache命令,能够使得cp/scp等命令在执行后立刻清理页面缓存。
  • 可以通过 cgroup memcg 限制用户的使用量,但是因为 pagecache 是全局共享的(有可能是别的group申请的),所以 memcg 只能保证 rss+pagecache 不超过内存配额,不能单独限制每个 group 的 pagecache 用量,只是在内存不足时 pagecache 会被直接丢掉,虽然提供了 group 级别的统计功能,这样要精确隔离的话,就得为这些命令建立单独一个 cgroup。
    • 从上可知 cgroup 也可以和 dd 一样,可以保证不额外占用 pagecache,即使是用来过渡,但 cgroup 一定要保证有 rss 和 anon 外有一定的最小额外内存,否则容易发生 OOM。
  • nginx
    • 增加 directio 512k 指令后,nginx 对于静态资源就会走直接 I/O 模式了,也只有增加了该指令才是真正的直接I/O。
    • sendfile(它调用的是系统调用 sendfile,但是 sendfile 默认情况下并不走 NOCACHE_IO 模式,所以仍然会走页面缓存。
  • 对于文件读写,curl 的 --no-buffer 选项好像并没有生效,这样要想实现低内存占用文件,就得使用 java nio 或 c direct io 自行实现。
  • java 虽然提供了大量的 I/O 接口,但是大部分上层接口都是基于文件系统缓存的。要操作底层就需要对 NIO 比较熟悉了,核心又是 DirectBuffer 和 ByteBuffer
    • java 原生并不支持O_DIRECT选项,这样有个缺点就是写大文件会占用pagecache、亦或性能受到影响,因为要每次映射一部分,

一些主要应用和命令对文件I/O的管理方式。

应用	    默认模式(依赖OS或自身管理)	        相关控制参数
oracle	    sga控制	                                filesystemio_options
mysql	    buffer_pool控制	                        innodb_flush_log_at_trx_commit
mongodb	    依赖于操作系统	 
c	        通过 open 文件带上 O_DIRECT 参数,
            直接写到设备上。	 
java	    自己控制(文件读写除外),
            没有直接的参数控制	 
kafka	    scala写的,依赖于JVM,所以本质上也
            是自己控制,文件则依赖于OS	 
redis	    自己控制	                            maxmemory,提供了超过后的策略
zookeeper	跟kafka类似

cgroup

yum install libcgroup
service cgconfig start
cgcreate -a uft_trade_mysql -gmemory:memcg
cd /cgroup/memory/memcg/
cat memory.limit_in_bytes
echo 1048576 > memory.limit_in_bytes
echo $$ > tasks
cp a.dat.new ~/a.dat  # 限额 1M 时内存不足被OOM kill Killed

nginx 中的直接 I/O:

aio threads;
directio 512k;
output_buffers 1 8m;   # 其对性能会有高达10%的影响,用于设置从磁盘读取缓冲区响应的数量和大小。

TODO:

Linux 直接I/O 原理与实现
https://blog.csdn.net/qq_40989769/article/details/110645449
Linux操作系统I/O机制原理与实现(图文详解)
https://zhuanlan.zhihu.com/p/438526019
Java-NIO之Channel(通道)
https://blog.csdn.net/weixin_45566993/article/details/124096517
MMAP和DIRECT IO区别
https://www.cnblogs.com/zhaoyl/p/5901680.html
Java网络编程与NIO详解8:浅析mmap和Direct Buffer
https://blog.csdn.net/AliCoder/article/details/103039202

文件系统性能对比:https://blog.csdn.net/linkyy5/article/details/125955196

  • 高并发读写:btrfs 最优,xfs 及 ext4 稍好,zfs 及 ntfs 最差。
  • 随机读写:ntfs 最优,其余相差不大。
  • 顺序读写:ntfs 最优,btrfs 最差,其余相差不大
  • 顺序多文件写入:f2fs 最优,其余相差不大。
  • 并发多文件写入:ext4 最优,ntfs 最差,zfs 较弱,其余相差不大。
  • 顺序多文件写入不同子目录:f2fs 最优,其余相差不大。
  • 多客户使用体验:xfs 最优,ntfs 最差,reiserFS 较弱,其余皆优秀。

各个文件系统具有特性,且各有优缺点:

  • btrfs 仍处于开发阶段,其 COW (Copy On Write) 机制使其对数据库的插入操作表现较差。
  • xfs 和 ext4 的综合素质优秀,特定能力上不会过于耀眼,但是对用户来说综合体验最佳。
  • f2fs 在多文件情境下表现出色。
  • reiserFS 即将被 reiser4 文件系统取代,综合性能大不及其它系统。
  • ntfs 在串行的工作模式下,其随机读写和顺序读写能力都极高;反之,其在高并发高压环境下表现不佳。

许多文件系统并不一定专门为性能而生,它们都有自己的适用场景,每个文件系统都有其独特的设计初衷。例如:

  • btrfs 和 zfs 都具有 COW(Copy On Write) 机制。COW 机制使得它们在进行修改操作时具有不俗的性能,但也带来了磁盘空间的浪费,并增加了读取时的消耗。
  • btrfs 和 zfs 都自带 raid 功能。在数据可用性有要求的情况下,相比其他的文件系统,它们能提供开箱即用的 raid 阵列能力。
  • btrfs 对所有数据都带有 checksum 机制,确保文件完整性。
  • xfs 具有动态 inode 分配能力,适合大文件分配。

陈炽卉 AIX 性能管理与监控建议
http://www.360doc.com/content/22/0629/22/2245786_1038015973.shtml

How to check disk I/O utilization per process?
https://serverfault.com/questions/169676/how-to-check-disk-i-o-utilization-per-process

iotop
pidstat -dl 20
cut -d" " -f 1,2,42 /proc/[0-9]*/stat | sort -n -k +3

atop -a -w historical_everything.atop 10 1080 &
atop -r historical_everything.atop

    t - move forward to the next data gathering (10 seconds)
    d - show the disk io oriented information per process
    D - sort the processes based on disk activity
    T - go backwards 1 data point (10 seconds probably)
    h - bring up help
    b - jump to a time (nearest prior datapoint) - e.g. b12:00 - only jumps forward
    1 - display per second instead of delta since last datapiont in the upper half of the display

sudo apt install blktrace
sudo btrace /dev/mapper/ubuntu--server--vg-root
date >>/tmp/wtf && ps -eo "cmd,pid,min_flt,maj_flt" >>/tmp/wtf

Amazon MySQL RDS迁移到Amazon Aurora并要求最小停机时间
https://aws.amazon.com/cn/blogs/china/every-scene-mysql-database-move-to-amazon-aurora/

Perf with GUI
https://oopsmonk.github.io/posts/2022-04-28-perf/
https://github.com/KDAB/hotspot

perf stat -d ./a.out

View size of CPU cache through the command-line?
https://askubuntu.com/questions/724449/view-size-of-cpu-cache-through-the-command-line

lscpu | grep "cache"
getconf -a | grep CACHE

How to Use the time Command on Linux
https://www.howtogeek.com/415977/how-to-use-the-time-command-on-linux/

Using a \ character before the command name is the same as using command before the command name.

\time -f "Program: %C\nTotal time: %E\nUser Mode (s) %U\nKernel Mode (s) %S\nCPU: %P" sleep 1

游戏

  • GBA
    • 牧场物语:矿石镇的伙伴们
    • 最终幻想Advance
    • 恶魔城
    • 塞尔达传说缩小帽
    • 口袋妖怪
      • 精灵宝可梦红宝石·蓝宝石(2002-11-21)
      • 精灵宝可梦火红·叶绿(2004-01-29)
      • 精灵宝可梦绿宝石(2004-09-16)
      • 精灵宝可梦不可思议的迷宫:赤之救助队(2005-11-17)
    • 火焰纹章

马里奥大叔的所有资料
http://www.youxi131.com/wlyx/125604.html

PHP

显示错误
php -d display_errors=on artisan

mysql

查看 buffer pool

select @@innodb_buffer_pool_size / pow(2,30) as gibibytes;

按条件修改列

mysql> create database test;
Query OK, 1 row affected (0.01 sec)

mysql> use test;
Database changed
mysql> create table t1(c varchar(4));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into t1 values (1),(2),(3);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from t1;
+------+
| c    |
+------+
| 1    |
| 2    |
| 3    |
+------+
3 rows in set (0.00 sec)

mysql> update t1 set c = case when c='1' then 'a' when c='2' then 'b' when c='3' then 'c' else c end;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> select * from t1;
+------+
| c    |
+------+
| a    |
| b    |
| c    |
+------+
3 rows in set (0.00 sec)

VIM

vim 里的正则搜索,有特殊的语法+要转义

/^[0-9]\+,[^,]\+\n

How do I jump to the location of my last edit?
https://vi.stackexchange.com/questions/2001/how-do-i-jump-to-the-location-of-my-last-edit

`.
g, g;
ctrl+O ctrl+I

跳转指令

% 跳转到相配对的括号
gD 跳转到局部变量的定义处
'' 跳转到光标上次停靠的地方, 是两个', 而不是一个"
mx 设置书签,x只能是a-z的26个字母
`x 跳转到书签处("`"是1左边的键)
> 增加缩进,"x>"表示增加以下x行的缩进
< 减少缩进,"x<"表示减少以下x行的缩进

{ 跳到上一段的开头
} 跳到下一段的的开头
( 移到这个句子的开头
) 移到下一个句子的开头

[[ 跳转至上一个函数(要求代码块中'{'必须单独占一行)
]] 跳转至下一个函数(要求代码块中'{'必须单独占一行)

C-] 跳转至函数或变量定义处
C-O 返回跳转前位置
C-T 同上
nC-T 返回跳转 n 次

0 数字0,跳转至行首
^ 跳转至行第一个非空字符
$ 跳转至行尾

python

Invalid control character with Python json.loads
https://stackoverflow.com/questions/22394235/invalid-control-character-with-python-json-loads

json_str = json.loads(jsonString, strict=False)