generated from cotes2020/chirpy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,901 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: 计算机单位换算 | ||
date: 2019-01-02 00:00:00 +0800 | ||
categories: [root, linux] | ||
tags: [linux] | ||
author: ahern | ||
--- | ||
|
||
### 位b(bit比特) | ||
- 二进制位 | ||
|
||
### 字节B(byte) | ||
- 1B = 8b | ||
|
||
### 字(word) | ||
- 计算机进行数据处理时,一次存取、加工和传送的数据长度 | ||
- 一个字通常由一个或多个(一般是字节的整数位)字节构成 | ||
- 如:64位系统字的长度为64 | ||
|
||
### K | ||
- 1K = 1024B = 2^10B 约 10^3B | ||
|
||
### M | ||
- 1M = 1024K = 2^20B 约 10^6B | ||
|
||
### G | ||
- 1G = 1024M = 2^30B 约 10^9B | ||
|
||
### logN | ||
- 2为底 | ||
|
||
### lgN | ||
- 10为底 | ||
|
||
### 1亿 | ||
- 10^8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: 常用Linux命令 | ||
date: 2019-05-19 00:00:00 +0800 | ||
categories: [root, linux] | ||
tags: [linux] | ||
author: ahern | ||
--- | ||
|
||
### chmod | ||
|
||
- chmod 777 filename | ||
- 编辑权限 | ||
- r=4,w=2,x=1 | ||
|
||
### find | ||
|
||
- find pathname -options | ||
- 查找文件 | ||
|
||
### ps | ||
|
||
- ps -ef | ||
- 查看进程信息 | ||
|
||
### top | ||
|
||
- 动态查看进程cpu、内存等系统资源占用情况 | ||
|
||
### ping | ||
|
||
- 检测是否与主机ip连通 | ||
|
||
### telnet | ||
|
||
- 探测主机下某个端口是否开放 | ||
|
||
### vim | ||
|
||
### lsof | ||
|
||
- -i 查看端口占用 | ||
|
||
- -p [端口号]:查看进程占用的文件描述符 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: 零拷贝 | ||
date: 2021-08-30 00:00:00 +0800 | ||
categories: [root, linux] | ||
tags: [linux] | ||
author: ahern | ||
--- | ||
|
||
### 高速缓存PageCache | ||
|
||
- 在内存中有一个分区用来缓存热点数据 | ||
- 有预读功能 | ||
- 读写速度比磁盘快 | ||
- 应用与内核态缓存区,如下文内核态缓存区 | ||
|
||
### DMA技术 | ||
|
||
- 在进行I/O设备(如:磁盘)和内存进行数据传输时,由DMA负责数据搬运,而不需要CPU参与 | ||
|
||
### 传统文件传输 | ||
|
||
- <img src="https://raw.githubusercontent.com/li-zeyuan/access/master/img/Snipaste_2022-02-18_14-51-45.png" alt="Snipaste_2022-02-18_14-51-45" style="zoom:50%;" /> | ||
- 系统调用:read(file, tmp_buf, len)、write(socket, tmp_buf, len) | ||
- 4次上下文切换:read两次+write两次 | ||
- 4次数据拷贝:2次DMA拷贝 + 2次CPU拷贝 | ||
|
||
### 零拷贝技术 | ||
|
||
- <img src="https://raw.githubusercontent.com/li-zeyuan/access/master/img/Snipaste_2022-02-18_15-04-04.png" alt="Snipaste_2022-02-18_15-04-04" style="zoom:50%;" /> | ||
- 零拷贝:数据传输过程中,**仅由DMA参与数据拷贝,CPU不参与** | ||
- 系统调用:sendfile(int out_fd, int in_fd, off_t *offset, size_t count) | ||
- 2次上下文切换:sendfile两次 | ||
- 2次数据拷贝:2次DMA拷贝 | ||
|
||
### 大文件传输 | ||
|
||
- <img src="https://raw.githubusercontent.com/li-zeyuan/access/master/img/Snipaste_2022-02-18_15-12-30.png" alt="Snipaste_2022-02-18_15-12-30" style="zoom:50%;" /> | ||
- 使用异步IO ,绕开PageCache,过程如图 | ||
- 为什么不用零拷贝? | ||
- 零拷贝使用了PageCache | ||
- 很快占满PageCache,导致热点小数据不能使用PageCache | ||
- 大文件PageCache命中率不高 | ||
|
||
### 参考 | ||
|
||
- 原来 8 张图,就可以搞懂「零拷贝」了:https://www.cnblogs.com/xiaolincoding/p/13719610.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
--- | ||
title: 进程、线程、协程 | ||
date: 2019-10-10 00:00:00 +0800 | ||
categories: [root, linux] | ||
tags: [linux] | ||
author: ahern | ||
--- | ||
|
||
### 异常进程 | ||
- 孤儿进程: | ||
- 父进程退出,子进程仍在运行,子进程成了孤儿进程 | ||
- 孤儿进程由init进程接管 | ||
|
||
- 僵尸进程: | ||
- 子进程退出,父进程没有**wait或waitpid**,子进程描述还存在进程中,这个子进程就成了僵尸进程 | ||
|
||
|
||
### 并发、并行 | ||
|
||
- 并发:一个CPU通过时间片轮询去调度多个程序,CPU同一时刻只能执行一个程序 | ||
- 并行:多个CPU同一时刻执行多个程序,程序间互不抢占CPU资源。 | ||
|
||
### 进程、线程、协程 | ||
|
||
- 进程 | ||
- 是操作系统资源分配的基本单元 | ||
- 三种状态:就绪、运行、阻塞 | ||
- 拥有独立的堆栈,进程间数据不共享 | ||
- 场景:CPU密集型 | ||
- 线程(go中没有直接创建线程的操作,go关键字创建的协程依赖于线程) | ||
- 是CPU调度的基本单位 | ||
- 存在于进程中,一个进程可以有多个线程 | ||
- 共享堆空间、不共享栈空间 | ||
- 由内核完成调度、上下文的切换 | ||
- 场景:IO密集型 | ||
- 协程 | ||
- 用户基于线程去创建,由用户程序去实现调度 | ||
- 共享堆空间、不共享栈空间 | ||
- go协程 | ||
- 本质上是协程,从语言层面上支持了协程 | ||
- 独立的栈,用于保存其运行状态和局部变量 | ||
- 共享堆,通过管道通信 | ||
- 用户态,由GMP调度模型调度 | ||
- 轻量级,开销小 | ||
- go关键字创建 | ||
|
||
### 进程间通讯 | ||
- 匿名管道 | ||
|
||
- 命令行"|" | ||
- 父子进程间通信 | ||
|
||
- 命名管道 | ||
|
||
- 命令:mkfifo | ||
- 两个进程间通信 | ||
|
||
``` | ||
匿名、命名管道本质是在内核中一块缓冲区 | ||
优点:简单方便 | ||
缺点:随机进程生命周期结束而结束 | ||
``` | ||
|
||
- 消息队列 | ||
|
||
- 保存在内核中的消息链表 | ||
- 优点:生命周期随核 | ||
- 缺点:消息不及时 | ||
- 缺点:用户态内核态频繁拷贝,效率低 | ||
|
||
- 共享内存 | ||
|
||
- 两个进程的一部分虚拟内存共同映射用一个块物理内存 | ||
- 场景:键盘输入,打印进程打印 | ||
|
||
|
||
- 信号量 | ||
- **实现进程间互斥和同步,并不是实现进程间数据互通** | ||
- 场景:值为1的互斥信号量 | ||
- 场景:值为0的同步信号量 | ||
- 信号 | ||
- 异步通信机制 | ||
- 如:kill | ||
- socket | ||
- 不同主机,进程间通信 | ||
- 场景:TCP\UDP | ||
|
||
- 【参考】 | ||
- https://www.cnblogs.com/xiaolincoding/p/13402297.html | ||
|
||
|
||
### 线程分类 | ||
|
||
- 内核线程:存在于内核态 | ||
- 处理器竞争:可以在全系统范围内竞争处理器资源。 | ||
- 使用资源:内核栈和上下文切换时保持寄存器的空间 | ||
- 调度:调度开销和进程差不多 | ||
- 轻量级线程:抽象于内核线程之上,仅保留上下文信息,和调度程序所需要的统计信息 | ||
- 处理器竞争:与特定的内核线程关联,可以在全系统范围内竞争处理器资源。 | ||
- 使用资源:与父进程共享进程地址空间 | ||
- 调度:由内核管理,像普通进程一样调度 | ||
- 用户线程:由用户创建、调度、同步、销毁,不需要内核参与 | ||
- 处理器竞争:线程间竞争所属进程的资源 | ||
- 使用资源:与所属进程共享进程地址空间和系统资源 | ||
- 调度:由进程实现调度 | ||
|
||
### 进程间切换与线程间切换的区别 | ||
https://blog.csdn.net/xiangwanpeng/article/details/78196539?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-9-78196539.pc_agg_new_rank&utm_term=%E7%BA%BF%E7%A8%8B%E4%B9%8B%E9%97%B4%E6%80%8E%E4%B9%88%E5%88%87%E6%8D%A2&spm=1000.2123.3001.4430 | ||
- 进程切换 | ||
- 切换虚拟内存,切换页表 | ||
- 刷新页表缓冲 | ||
- 线程切换 | ||
- 切换上下文,寄存器内容换出 | ||
- 参考: | ||
- https://blog.csdn.net/dan15188387481/article/details/49450491 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: 死锁 | ||
date: 2019-12-20 00:00:00 +0800 | ||
categories: [root, linux] | ||
tags: [linux] | ||
author: ahern | ||
--- | ||
|
||
### 死锁四大条件 | ||
- 互斥条件:资源在一个时间段内只能为一个进程使用,其他进程阻塞等待 | ||
- 保持与请求条件:进程在保持占有一个资源,又请求新资源 | ||
- 不可剥夺条件:进程占用的资源只能由该进程释放 | ||
- 循环等待条件:多个进程形成循环等待资源释放 | ||
|
||
### 死锁处理方式(根据死锁产生的前中后) | ||
|
||
#### 预防死锁 | ||
- 破坏死锁产生条件 | ||
|
||
#### 避免死锁 | ||
- 银行家算法 | ||
- 加锁顺序 | ||
- 加锁时限 | ||
|
||
#### 检测死锁 | ||
- 由操作系统实现死锁检测进程,若产生死锁,执行解除死锁 | ||
|
||
#### 解除死锁 | ||
- 撤销进程法 | ||
- 进程回退法 | ||
|
||
#### go死锁场景 | ||
- goroutine无限阻塞chan | ||
- mysql事务行锁导致死锁 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: 海量数据求top K问题 | ||
date: 2020-01-19 00:00:00 +0800 | ||
categories: [root, algorithm] | ||
tags: [algorithm] | ||
author: ahern | ||
--- | ||
|
||
### 问题:海量数据求top K问题 | ||
- https://blog.csdn.net/zyq522376829/article/details/47686867 | ||
- 10亿个数中找出最大的10000个数 | ||
|
||
### 方式1:排序(快排) | ||
- 时间复杂度:O(NlogN) | ||
- 空间复杂度:O(NlogN) | ||
|
||
### 方式2:局部淘汰 | ||
- 1、定义一个数组存储最大10000个数 | ||
- 2、遍历10亿数,与最大数数组的最小数对比,大于则加入最大数数组 | ||
- 时间复杂度:O(N + (M*N)) | ||
- 空间复杂度:O(1) | ||
|
||
### 方式3:归并(分治) | ||
- 1、10亿数据分成若干份 | ||
- 2、找出每一个份的前10000个数,得100万个数 | ||
- 3、对100万个数划分为二,分治 | ||
- 时间复杂度:常数 | ||
|
||
### 方式4:最小堆 | ||
- 1、10000个数建最小堆 | ||
- 2、遍历剩下的数,和堆顶对比,比堆顶大则替换,重新建堆 | ||
- 时间复杂度:O(Nmlogm) | ||
- 空间复杂度:堆原地排序,O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: 哈稀算法 | ||
date: 2020-02-20 00:00:00 +0800 | ||
categories: [root, algorithm] | ||
tags: [algorithm] | ||
author: ahern | ||
--- | ||
|
||
## 哈稀算法 | ||
|
||
## 一致性哈稀算法 | ||
- **尽可能少改变已存在的请求**与处理请求服务器之间的映射关系 | ||
- 解决分布式系统中简单哈稀存在的动态伸缩问题 | ||
|
||
### 优点 | ||
- 可扩展 | ||
|
||
### 缺点 | ||
- 分布不均匀 | ||
- 解决:虚拟节点,虚拟节点放在哈稀环,虚拟节点指向物理服务组 |
Oops, something went wrong.