From 56b9bae38171399d86c8ff764ab5533e89212f4a Mon Sep 17 00:00:00 2001 From: nicksxs Date: Sun, 8 Mar 2020 23:27:49 +0800 Subject: [PATCH] Site updated: 2020-03-08 23:27:48 --- 2014/12/23/my-new-post/index.html | 8 +- 2014/12/24/MFC 模态对话框/index.html | 12 +- 2014/12/30/Clone-Graph-Part-I/index.html | 22 +- 2015/01/04/Path-Sum/index.html | 18 +- 2015/01/14/Two-Sum/index.html | 18 +- .../index.html | 16 +- 2015/03/11/Number-Of-1-Bits/index.html | 16 +- 2015/03/11/Reverse-Bits/index.html | 18 +- 2015/03/13/Reverse-Integer/index.html | 18 +- 2015/04/14/Add-Two-Number/index.html | 18 +- 2015/04/15/Leetcode-No-3/index.html | 18 +- 2015/06/22/invert-binary-tree/index.html | 18 +- 2016/07/13/swoole-websocket-test/index.html | 8 +- 2016/08/14/34-Search-for-a-Range/index.html | 18 +- 2016/08/14/docker-mysql-cluster/index.html | 8 +- 2016/09/29/binary-watch/index.html | 18 +- .../minimum-size-subarray-sum-209/index.html | 18 +- 2016/10/12/summary-ranges-228/index.html | 18 +- .../index.html | 8 +- 2017/03/28/spark-little-tips/index.html | 8 +- 2017/04/25/rabbitmq-tips/index.html | 12 +- 2017/05/09/ambari-summary/index.html | 8 +- 2019/06/18/openresty/index.html | 8 +- .../23/AbstractQueuedSynchronizer/index.html | 8 +- 2019/12/07/JVM-G1-Part-1/index.html | 28 +- 2019/12/10/Redis-Part-1/index.html | 8 +- 2019/12/18/1Q84读后感/index.html | 20 +- .../聊聊Java中的单例模式/index.html | 8 +- 2019/12/26/redis数据结构介绍/index.html | 12 +- .../04/redis数据结构介绍二/index.html | 8 +- .../10/redis数据结构介绍三/index.html | 8 +- .../19/redis数据结构介绍四/index.html | 12 +- .../20/redis数据结构介绍五/index.html | 12 +- .../22/redis数据结构介绍六/index.html | 12 +- 2020/02/01/2019年终总结/index.html | 8 +- 2020/02/09/G1收集器概述/index.html | 26 +- 2020/02/16/Maven实用小技巧/index.html | 8 +- .../index.html | 8 +- 2020/03/01/寄生虫观后感/index.html | 13 +- .../index.html | 693 ++++++++++++++++++ 404.html | 8 +- 404/index.html | 8 +- archives/2014/12/index.html | 10 +- archives/2014/index.html | 10 +- archives/2015/01/index.html | 10 +- archives/2015/03/index.html | 10 +- archives/2015/04/index.html | 10 +- archives/2015/06/index.html | 10 +- archives/2015/index.html | 10 +- archives/2016/07/index.html | 10 +- archives/2016/08/index.html | 10 +- archives/2016/09/index.html | 10 +- archives/2016/10/index.html | 10 +- archives/2016/11/index.html | 10 +- archives/2016/index.html | 10 +- archives/2017/03/index.html | 10 +- archives/2017/04/index.html | 10 +- archives/2017/05/index.html | 10 +- archives/2017/index.html | 10 +- archives/2019/06/index.html | 10 +- archives/2019/09/index.html | 10 +- archives/2019/12/index.html | 10 +- archives/2019/index.html | 10 +- archives/2020/01/index.html | 10 +- archives/2020/02/index.html | 10 +- archives/2020/03/index.html | 30 +- archives/2020/index.html | 53 +- archives/2020/page/2/index.html | 507 +++++++++++++ archives/index.html | 50 +- archives/page/2/index.html | 53 +- archives/page/3/index.html | 53 +- archives/page/4/index.html | 30 +- atom.xml | 89 +-- baidu_verify_Gl8jtoDV4z.html | 8 +- baidusitemap.xml | 19 +- categories/C/Redis/index.html | 8 +- categories/C/index.html | 8 +- categories/Java/Design-Patterns/index.html | 8 +- categories/Java/GC/index.html | 8 +- categories/Java/JVM/index.html | 8 +- categories/Java/Maven/index.html | 8 +- categories/Java/Singleton/index.html | 8 +- categories/Java/index.html | 179 ++--- categories/Redis/Distributed-Lock/index.html | 8 +- categories/Redis/index.html | 8 +- categories/Redis/数据结构/index.html | 8 +- categories/Redis/源码/index.html | 8 +- categories/data-analysis/index.html | 8 +- categories/docker/index.html | 14 +- categories/docker/介绍/index.html | 514 +++++++++++++ categories/index.html | 12 +- categories/leetcode/index.html | 8 +- categories/leetcode/page/2/index.html | 8 +- categories/nginx/index.html | 8 +- categories/php/index.html | 8 +- categories/持续集成/index.html | 8 +- categories/生活/index.html | 8 +- .../生活/年终总结/2019/index.html | 8 +- categories/生活/年终总结/index.html | 8 +- categories/生活/影评/2020/index.html | 8 +- categories/生活/影评/index.html | 8 +- categories/读后感/index.html | 8 +- categories/读后感/村上春树/index.html | 8 +- css/main.css | 2 +- index.html | 271 +++---- lib/pace/README.html | 8 +- page/2/index.html | 248 ++++--- page/3/index.html | 205 +++--- page/4/index.html | 109 ++- sitemap.xml | 23 +- tags/2019/index.html | 8 +- tags/Design-Patterns/index.html | 8 +- tags/Distributed-Lock/index.html | 8 +- tags/G1/index.html | 8 +- tags/GC/index.html | 8 +- tags/Garbage-First-Collector/index.html | 8 +- tags/Gogs/index.html | 8 +- tags/JVM/index.html | 8 +- tags/Maven/index.html | 8 +- tags/Redis/index.html | 8 +- tags/Singleton/index.html | 8 +- tags/Webhook/index.html | 8 +- tags/aqs/index.html | 8 +- tags/c/index.html | 8 +- tags/c/page/2/index.html | 8 +- tags/cgroup/index.html | 514 +++++++++++++ tags/cluster/index.html | 8 +- tags/docker/index.html | 14 +- tags/hadoop/index.html | 8 +- tags/im/index.html | 8 +- tags/index.html | 12 +- tags/java/index.html | 132 ++-- tags/leetcode/index.html | 8 +- tags/leetcode/page/2/index.html | 8 +- tags/mfc/index.html | 8 +- tags/mq/index.html | 8 +- tags/mysql/index.html | 8 +- tags/namespace/index.html | 514 +++++++++++++ tags/nginx/index.html | 8 +- tags/openresty/index.html | 8 +- tags/php/index.html | 8 +- tags/python/index.html | 8 +- tags/spark/index.html | 8 +- tags/swoole/index.html | 8 +- tags/websocket/index.html | 8 +- tags/分布式锁/index.html | 8 +- tags/单例/index.html | 8 +- tags/博客,文章/index.html | 8 +- tags/寄生虫/index.html | 8 +- tags/年终总结/index.html | 8 +- tags/影评/index.html | 8 +- tags/数据结构/index.html | 8 +- tags/源码/index.html | 8 +- tags/生活/index.html | 8 +- tags/设计模式/index.html | 8 +- tags/读后感/index.html | 8 +- 156 files changed, 4279 insertions(+), 1374 deletions(-) create mode 100644 2020/03/08/docker比一般多一点的初学者介绍/index.html create mode 100644 archives/2020/page/2/index.html create mode 100644 categories/docker/介绍/index.html create mode 100644 tags/cgroup/index.html create mode 100644 tags/namespace/index.html diff --git a/2014/12/23/my-new-post/index.html b/2014/12/23/my-new-post/index.html index efe6b32d6a..04804bee36 100644 --- a/2014/12/23/my-new-post/index.html +++ b/2014/12/23/my-new-post/index.html @@ -438,20 +438,20 @@
- 39 + 40 posts
- 27 + 29 categories
- 45 + 48 tags
@@ -476,7 +476,7 @@
diff --git a/2014/12/24/MFC 模态对话框/index.html b/2014/12/24/MFC 模态对话框/index.html index 99755c1716..9a685133cf 100644 --- a/2014/12/24/MFC 模态对话框/index.html +++ b/2014/12/24/MFC 模态对话框/index.html @@ -310,13 +310,13 @@ @@ -479,20 +479,20 @@
- 39 + 40 posts
- 27 + 29 categories
- 45 + 48 tags
@@ -517,7 +517,7 @@
diff --git a/2015/03/11/Number-Of-1-Bits/index.html b/2015/03/11/Number-Of-1-Bits/index.html index bca0f3dcf7..9d0612a841 100644 --- a/2015/03/11/Number-Of-1-Bits/index.html +++ b/2015/03/11/Number-Of-1-Bits/index.html @@ -308,16 +308,16 @@ @@ -386,9 +386,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/categories/docker/介绍/index.html b/categories/docker/介绍/index.html new file mode 100644 index 0000000000..f417e619ea --- /dev/null +++ b/categories/docker/介绍/index.html @@ -0,0 +1,514 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Category: 介绍 | Nicksxs's Blog + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ + +

What hurts more, the pain of hard work or the pain of regret?

+
+ + +
+ + + +
+
+ + +
+ + 0% +
+ + + + +
+
+
+ + +
+ + + + + +
+
+
+

介绍 + Category +

+
+ + +
+

2020

+
+ + + +
+
+ + + + + + + + +
+ + + + +
+ + + + + + + + +
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/categories/index.html b/categories/index.html index 2704bc34c5..f362ac87d7 100644 --- a/categories/index.html +++ b/categories/index.html @@ -249,10 +249,10 @@
@@ -332,20 +332,20 @@ @@ -370,7 +370,7 @@ diff --git a/categories/leetcode/index.html b/categories/leetcode/index.html index 7c90c7e869..fbaad02a7b 100644 --- a/categories/leetcode/index.html +++ b/categories/leetcode/index.html @@ -516,20 +516,20 @@ @@ -554,7 +554,7 @@ diff --git a/categories/leetcode/page/2/index.html b/categories/leetcode/page/2/index.html index da011c9641..e056b766f1 100644 --- a/categories/leetcode/page/2/index.html +++ b/categories/leetcode/page/2/index.html @@ -376,20 +376,20 @@ @@ -414,7 +414,7 @@ diff --git a/categories/nginx/index.html b/categories/nginx/index.html index 5185429755..7918ac8f3e 100644 --- a/categories/nginx/index.html +++ b/categories/nginx/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/categories/php/index.html b/categories/php/index.html index 2ccb7472d0..2071beb2b0 100644 --- a/categories/php/index.html +++ b/categories/php/index.html @@ -373,20 +373,20 @@ @@ -411,7 +411,7 @@ diff --git a/categories/持续集成/index.html b/categories/持续集成/index.html index d144db6b21..8c78e23362 100644 --- a/categories/持续集成/index.html +++ b/categories/持续集成/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/categories/生活/index.html b/categories/生活/index.html index a039d01370..eba0b39bed 100644 --- a/categories/生活/index.html +++ b/categories/生活/index.html @@ -373,20 +373,20 @@ @@ -411,7 +411,7 @@ diff --git a/categories/生活/年终总结/2019/index.html b/categories/生活/年终总结/2019/index.html index cd5a0e0c80..0875f79f85 100644 --- a/categories/生活/年终总结/2019/index.html +++ b/categories/生活/年终总结/2019/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/categories/生活/年终总结/index.html b/categories/生活/年终总结/index.html index eb51199c05..1faea2612d 100644 --- a/categories/生活/年终总结/index.html +++ b/categories/生活/年终总结/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/categories/生活/影评/2020/index.html b/categories/生活/影评/2020/index.html index 20ceb0e682..2659b4f33d 100644 --- a/categories/生活/影评/2020/index.html +++ b/categories/生活/影评/2020/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/categories/生活/影评/index.html b/categories/生活/影评/index.html index ea9fd069fc..764098d77c 100644 --- a/categories/生活/影评/index.html +++ b/categories/生活/影评/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/categories/读后感/index.html b/categories/读后感/index.html index e6cd0d6d5e..41c68ed202 100644 --- a/categories/读后感/index.html +++ b/categories/读后感/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/categories/读后感/村上春树/index.html b/categories/读后感/村上春树/index.html index d8dc1ffd74..d0df0d658e 100644 --- a/categories/读后感/村上春树/index.html +++ b/categories/读后感/村上春树/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/css/main.css b/css/main.css index 802328c7bc..d99f1c3601 100644 --- a/css/main.css +++ b/css/main.css @@ -1259,7 +1259,7 @@ pre .javascript .function { } .links-of-author a::before, .links-of-author span.exturl::before { - background: #ee8333; + background: #d7d7ff; border-radius: 50%; content: ' '; display: inline-block; diff --git a/index.html b/index.html index 5fdae8f3c2..678999ce7a 100644 --- a/index.html +++ b/index.html @@ -225,6 +225,137 @@ +
+ + + + + +
+

+ + +

+ + +
+ + + + +
+ + +

因为最近想搭一个phabricator用来做看板和任务管理,一开始了解这个是Easy大大有在微博推荐过,后来苏洋也在群里和博客里说到了,看上去还不错的样子,因为主角是docker所以就不介绍太多,后面有机会写一下。

+

docker最开始是之前在某位大佬的博客看到的,看上去有点神奇,感觉是一种轻量级的虚拟机,但是能做的事情好像差不多,那时候是在Ubuntu系统的vps里起一个Ubuntu的docker,然后在里面装个nginx,配置端口映射就可以访问了,后来也草草写过一篇使用docker搭建mysql集群,但是最近看了下好像是因为装docker的大佬做了一些别名还是什么操作,导致里面用的操作都不具有普遍性,而且主要是把搭的过程写了下,属于囫囵吞枣,没理解docker是干啥的,为啥用docker,就是操作了下,这几天借着搭phabricator的过程,把一些原来不理解,或者原来理解错误的地方重新理一下。

+

之前写的 mysql 集群,一主二备,这种架构在很多小型应用里都是这么配置的,而且一般是直接在三台 vps 里启动三个 mysql 实例,但是如果换成 docker 会有什么好处呢,其实就是方便部署,比如其中一台备库挂了,我要加一台,或者说备库的 qps 太高了,需要再加一个,如果要在 vps 上搭建的话,首先要买一台机器,等初始化,然后在上面修改源,更新,装 mysql ,然后配置主从,可能还要处理防火墙等等,如果把这些打包成一个 docker 镜像,并且放在自己的 docker registry,那就直接run 一下就可以了;还有比如在公司要给一个新同学整一套开发测试环境,以 Java 开发为例,要装 git,maven,jdk,配置 maven settings 和各种 rc,整合在一个镜像里的话,就会很方便了;再比如微服务的水平扩展。

+

但是为啥 docker 会有这种优势,听起来好像虚拟机也可以干这个事,但是虚拟机动辄上 G,而且需要 VMware,virtual box 等支持,不适合在Linux服务器环境使用,而且占用资源也会非常大。说得这么好,那么 docker 是啥呢

+

docker 主要使用 Linux 中已经存在的两种技术的一个整合升级,一个是 namespace,一个是cgroups,相比于虚拟机需要完整虚拟出一个操作系统运行基础,docker 基于宿主机内核,通过 namespace 和 cgroups 分隔进程,理念就是提供一个隔离的最小化运行依赖,这样子相对于虚拟机就有了巨大的便利性,具体的 namespace 和 cgroups 就先不展开讲,可以参考耗子叔的文章

+

安装

那么我们先安装下 docker,参考官方的教程,安装,我的系统是 ubuntu 的,就贴了 ubuntu 的链接,用其他系统的可以找到对应的系统文档安装,安装完了的话看看 docker 的信息

+
1
sudo docker info
+ +

输出以下信息
IJP157hLqlgo4Ow

+

简单运行

然后再来运行个 hello world 呗,

+
1
sudo docker run hello-world
+ +

输出了这些
7dO2JWbf3wVLPsN

+

看看这个运行命令是怎么用的,一般都会看到这样子的,sudo docker run -it ubuntu bash, 前面的 docker run 反正就是运行一个容器的意思,-it是啥呢,还有这个什么 ubuntu bash,来看看docker run`的命令帮助信息

+
1
-i, --interactive                    Keep STDIN open even if not attached
+ +

就是要有输入,我们运行的时候能输入

+
1
-t, --tty                            Allocate a pseudo-TTY
+ +

要有个虚拟终端,

+
1
2
3
Usage:	docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container
+ +

镜像

上面说的-it 就是这里的 options,后面那个 ubuntu 就是 image 辣,image 是啥呢

+

Docker 把应用程序及其依赖,打包在 image 文件里面,可以把它理解成为类似于虚拟机的镜像或者运行一个进程的代码,跑起来了的叫docker 容器或者进程,比如我们将要运行的docker run -it ubuntu bash的ubuntu 就是个 ubuntu 容器的镜像,将这个镜像运行起来后,我们可以进入容器像使用 ubuntu 一样使用它,来看下我们的镜像

+

G3ltzyVLqheDRgo

+

一个 ubuntu 镜像才 64MB,非常小巧,然后是后面的bash,我通过交互式启动了一个 ubuntu 容器,然后在这个启动的容器里运行了 bash 命令,这样就可以在容器里玩一下了

+

在容器里看下进程,

2qQFPbxB9uEzcrJ

+

只有刚才运行容器的 bash 进程和我刚执行的 ps,这里有个可以注意下的,bash 这个进程的 pid 是 1,其实这里就用到了 linux 中的PID Namespace,容器会隔离出一个 pid 的名字空间,这里面的进程跟外部的 pid 命名独立

+

查看宿主机上的容器

1
sudo docker ps -a
+ +

spGtzcDXKv3ORU7

+

如何进入一个正在运行中的 docker 容器

这个应该是比较常用的,因为比如是一个微服务容器,有时候就像看下运行状态,日志啥的

+
1
sudo docker exec -it [containerID] bash
+ +

uswmh3Izp65kc9n

+

查看日志

1
sudo docker logs [containerID]
+ +

我在运行容器的终端里胡乱输入点啥,然后通过上面的命令就可以看到啦

+

RJAvlhEMD7VfbXz

+

L4YRni95lBzEmFh

+ + +
+ + + + + + +
+
+
+
+ + + + + + +
@@ -590,20 +721,20 @@ - , - , - , @@ -1277,126 +1408,6 @@ - - - -
- - - - - -
-

- - -

- - -
- - - - -
- - -

跳表 skiplist

跳表是个在我们日常的代码中不太常用到的数据结构,相对来讲就没有像数组,链表,字典,散列,树等结构那么熟悉,所以就从头开始分析下,首先是链表,跳表跟链表都有个表字(太硬扯了我🤦‍♀️),注意这是个有序链表

如上图,在这个链表里如果我要找到 23,是不是我需要从3,5,9开始一直往后找直到找到 23,也就是说时间复杂度是 O(N),N 的一次幂复杂度,那么我们来看看第二个

这个结构跟原先有点不一样,它给链表中偶数位的节点又加了一个指针把它们链接起来,这样子当我们要寻找 23 的时候就可以从原来的一个个往下找变成跳着找,先找到 5,然后是 10,接着是 19,然后是 28,这时候发现 28 比 23 大了,那我在退回到 19,然后从下一层原来的链表往前找,

这里毛估估是不是前面的节点我就少找了一半,有那么点二分法的意思。
前面的其实是跳表的引子,真正的跳表其实不是这样,因为上面的其实有个比较大的问题,就是插入一个元素后需要调整每个元素的指针,在 redis 中的跳表其实是做了个随机层数的优化,因为沿着前面的例子,其实当数据量很大的时候,是不是层数越多,其查询效率越高,但是随着层数变多,要保持这种严格的层数规则其实也会增大处理复杂度,所以 redis 插入每个元素的时候都是使用随机的方式,看一眼代码

-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* ZSETs use a specialized version of Skiplists */
typedef struct zskiplistNode {
sds ele;
double score;
struct zskiplistNode *backward;
struct zskiplistLevel {
struct zskiplistNode *forward;
unsigned long span;
} level[];
} zskiplistNode;

typedef struct zskiplist {
struct zskiplistNode *header, *tail;
unsigned long length;
int level;
} zskiplist;

typedef struct zset {
dict *dict;
zskiplist *zsl;
} zset;
-

忘了说了,redis 是把 skiplist 跳表用在 zset 里,zset 是个有序的集合,可以看到 zskiplist 就是个跳表的结构,里面用 header 保存跳表的表头,tail 保存表尾,还有长度和最大层级,具体的跳表节点元素使用 zskiplistNode 表示,里面包含了 sds 类型的元素值,double 类型的分值,用来排序,一个 backward 后向指针和一个 zskiplistLevel 数组,每个 level 包含了一个前向指针,和一个 span,span 表示的是跳表前向指针的跨度,这里再补充一点,前面说了为了灵活这个跳表的新增修改,redis 使用了随机层高的方式插入新节点,但是如果所有节点都随机到很高的层级或者所有都很低的话,跳表的效率优势就会减小,所以 redis 使用了个小技巧,贴下代码

-
1
2
3
4
5
6
7
#define ZSKIPLIST_P 0.25      /* Skiplist P = 1/4 */
int zslRandomLevel(void) {
int level = 1;
while ((random()&0xFFFF) < (ZSKIPLIST_P * 0xFFFF))
level += 1;
return (level<ZSKIPLIST_MAXLEVEL) ? level : ZSKIPLIST_MAXLEVEL;
}
-

当随机值跟0xFFFF进行与操作小于ZSKIPLIST_P * 0xFFFF时才会增大 level 的值,因此保持了一个相对递减的概率
可以简单分析下,当 random() 的值小于 0xFFFF 的 1/4,才会 level + 1,就意味着当有 1 - 1/4也就是3/4的概率是直接跳出,所以一层的概率是3/4,也就是 1-P,二层的概率是 P*(1-P),三层的概率是 P² * (1-P) 依次递推。

- - -
- - - - - - -
-
-
-
- - - -
@@ -1469,20 +1480,20 @@
- 39 + 40 posts
- 27 + 29 categories
- 45 + 48 tags
@@ -1507,7 +1518,7 @@
diff --git a/lib/pace/README.html b/lib/pace/README.html index 29f0612779..e07203f45c 100644 --- a/lib/pace/README.html +++ b/lib/pace/README.html @@ -373,20 +373,20 @@
- 39 + 40 posts
- 27 + 29 categories
- 45 + 48 tags
@@ -411,7 +411,7 @@
diff --git a/page/2/index.html b/page/2/index.html index f9b07730c8..84893428b8 100644 --- a/page/2/index.html +++ b/page/2/index.html @@ -225,6 +225,126 @@ +
+ + + + + +
+

+ + +

+ + +
+ + + + +
+ + +

跳表 skiplist

跳表是个在我们日常的代码中不太常用到的数据结构,相对来讲就没有像数组,链表,字典,散列,树等结构那么熟悉,所以就从头开始分析下,首先是链表,跳表跟链表都有个表字(太硬扯了我🤦‍♀️),注意这是个有序链表

如上图,在这个链表里如果我要找到 23,是不是我需要从3,5,9开始一直往后找直到找到 23,也就是说时间复杂度是 O(N),N 的一次幂复杂度,那么我们来看看第二个

这个结构跟原先有点不一样,它给链表中偶数位的节点又加了一个指针把它们链接起来,这样子当我们要寻找 23 的时候就可以从原来的一个个往下找变成跳着找,先找到 5,然后是 10,接着是 19,然后是 28,这时候发现 28 比 23 大了,那我在退回到 19,然后从下一层原来的链表往前找,

这里毛估估是不是前面的节点我就少找了一半,有那么点二分法的意思。
前面的其实是跳表的引子,真正的跳表其实不是这样,因为上面的其实有个比较大的问题,就是插入一个元素后需要调整每个元素的指针,在 redis 中的跳表其实是做了个随机层数的优化,因为沿着前面的例子,其实当数据量很大的时候,是不是层数越多,其查询效率越高,但是随着层数变多,要保持这种严格的层数规则其实也会增大处理复杂度,所以 redis 插入每个元素的时候都是使用随机的方式,看一眼代码

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* ZSETs use a specialized version of Skiplists */
typedef struct zskiplistNode {
sds ele;
double score;
struct zskiplistNode *backward;
struct zskiplistLevel {
struct zskiplistNode *forward;
unsigned long span;
} level[];
} zskiplistNode;

typedef struct zskiplist {
struct zskiplistNode *header, *tail;
unsigned long length;
int level;
} zskiplist;

typedef struct zset {
dict *dict;
zskiplist *zsl;
} zset;
+

忘了说了,redis 是把 skiplist 跳表用在 zset 里,zset 是个有序的集合,可以看到 zskiplist 就是个跳表的结构,里面用 header 保存跳表的表头,tail 保存表尾,还有长度和最大层级,具体的跳表节点元素使用 zskiplistNode 表示,里面包含了 sds 类型的元素值,double 类型的分值,用来排序,一个 backward 后向指针和一个 zskiplistLevel 数组,每个 level 包含了一个前向指针,和一个 span,span 表示的是跳表前向指针的跨度,这里再补充一点,前面说了为了灵活这个跳表的新增修改,redis 使用了随机层高的方式插入新节点,但是如果所有节点都随机到很高的层级或者所有都很低的话,跳表的效率优势就会减小,所以 redis 使用了个小技巧,贴下代码

+
1
2
3
4
5
6
7
#define ZSKIPLIST_P 0.25      /* Skiplist P = 1/4 */
int zslRandomLevel(void) {
int level = 1;
while ((random()&0xFFFF) < (ZSKIPLIST_P * 0xFFFF))
level += 1;
return (level<ZSKIPLIST_MAXLEVEL) ? level : ZSKIPLIST_MAXLEVEL;
}
+

当随机值跟0xFFFF进行与操作小于ZSKIPLIST_P * 0xFFFF时才会增大 level 的值,因此保持了一个相对递减的概率
可以简单分析下,当 random() 的值小于 0xFFFF 的 1/4,才会 level + 1,就意味着当有 1 - 1/4也就是3/4的概率是直接跳出,所以一层的概率是3/4,也就是 1-P,二层的概率是 P*(1-P),三层的概率是 P² * (1-P) 依次递推。

+ + +
+ + + + + + +
+
+
+
+ + + + + + +
@@ -502,12 +622,6 @@ - - - - , + , + + + @@ -740,20 +860,20 @@ - , - , - , @@ -1238,102 +1358,6 @@ - - - -
- - - - - -
-

- - -

- - -
- - - - -
- - -

spark 的一些粗浅使用经验

工作中学习使用了一下Spark做数据分析,主要是用spark的python接口,首先是pyspark.SparkContext(appName=xxx),这是初始化一个Spark应用实例或者说会话,不能重复,
返回的实例句柄就可以调用textFile(path)读取文本文件,这里的文本文件可以是HDFS上的文本文件,也可以普通文本文件,但是需要在Spark的所有集群上都存在,否则会
读取失败,parallelize则可以将python生成的集合数据读取后转换成rdd(A Resilient Distributed Dataset (RDD),一种spark下的基本抽象数据集),基于这个RDD就可以做
数据的流式计算,例如map reduce,在Spark中可以非常方便地实现

-

简单的mapreduce word count示例

1
2
3
4
textFile = sc.parallelize([(1,1), (2,1), (3,1), (4,1), (5,1),(1,1), (2,1), (3,1), (4,1), (5,1)])
data = textFile.reduceByKey(lambda x, y: x + y).collect()
for _ in data:
print(_)
- - -

结果

1
2
3
4
5
(3, 2)
(1, 2)
(4, 2)
(2, 2)
(5, 2)
- - -
- - - - - - -
-
-
-
- - - - @@ -1406,20 +1430,20 @@ @@ -1444,7 +1468,7 @@ diff --git a/page/3/index.html b/page/3/index.html index 51515cf419..d57404fb15 100644 --- a/page/3/index.html +++ b/page/3/index.html @@ -225,6 +225,102 @@ +
+ + + + + +
+

+ + +

+ + +
+ + + + +
+ + +

spark 的一些粗浅使用经验

工作中学习使用了一下Spark做数据分析,主要是用spark的python接口,首先是pyspark.SparkContext(appName=xxx),这是初始化一个Spark应用实例或者说会话,不能重复,
返回的实例句柄就可以调用textFile(path)读取文本文件,这里的文本文件可以是HDFS上的文本文件,也可以普通文本文件,但是需要在Spark的所有集群上都存在,否则会
读取失败,parallelize则可以将python生成的集合数据读取后转换成rdd(A Resilient Distributed Dataset (RDD),一种spark下的基本抽象数据集),基于这个RDD就可以做
数据的流式计算,例如map reduce,在Spark中可以非常方便地实现

+

简单的mapreduce word count示例

1
2
3
4
textFile = sc.parallelize([(1,1), (2,1), (3,1), (4,1), (5,1),(1,1), (2,1), (3,1), (4,1), (5,1)])
data = textFile.reduceByKey(lambda x, y: x + y).collect()
for _ in data:
print(_)
+ + +

结果

1
2
3
4
5
(3, 2)
(1, 2)
(4, 2)
(2, 2)
(5, 2)
+ + +
+ + + + + + +
+
+
+
+ + + + + + +
@@ -1117,107 +1213,6 @@ - - - -
- - - - - -
-

- - -

- - -
- - - - -
- - -

problem

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

-

Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

-

分析(不用英文装逼了)
这个代码是抄来的,链接原作是这位大大。

- -
- - Read more » - -
- - - -
- - - - - - -
-
-
-
- - - - @@ -1290,20 +1285,20 @@ @@ -1328,7 +1323,7 @@ diff --git a/page/4/index.html b/page/4/index.html index 02b463d234..f88b8f0707 100644 --- a/page/4/index.html +++ b/page/4/index.html @@ -225,6 +225,107 @@ +
+ + + + + +
+

+ + +

+ + +
+ + + + +
+ + +

problem

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

+

Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

+

分析(不用英文装逼了)
这个代码是抄来的,链接原作是这位大大。

+ +
+ + Read more » + +
+ + + +
+ + + + + + +
+
+
+
+ + + + + + +
@@ -1178,20 +1279,20 @@ @@ -1216,7 +1317,7 @@ diff --git a/sitemap.xml b/sitemap.xml index 82ed7dc2be..c773619f44 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -1,6 +1,13 @@ + + https://nicksxs.me/2020/03/08/docker%E6%AF%94%E4%B8%80%E8%88%AC%E5%A4%9A%E4%B8%80%E7%82%B9%E7%9A%84%E5%88%9D%E5%AD%A6%E8%80%85%E4%BB%8B%E7%BB%8D/ + + 2020-03-08T15:27:19.890Z + + + https://nicksxs.me/2020/03/01/%E5%AF%84%E7%94%9F%E8%99%AB%E8%A7%82%E5%90%8E%E6%84%9F/ @@ -93,28 +100,28 @@ - https://nicksxs.me/2015/01/14/Two-Sum/ + https://nicksxs.me/2019/12/10/Redis-Part-1/ 2020-01-12T13:08:27.015Z - https://nicksxs.me/2019/12/10/Redis-Part-1/ + https://nicksxs.me/2015/01/14/Two-Sum/ 2020-01-12T13:08:27.015Z - https://nicksxs.me/2016/11/10/php-abstract-class-and-interface/ + https://nicksxs.me/2016/09/29/binary-watch/ 2020-01-12T13:08:27.014Z - https://nicksxs.me/2016/09/29/binary-watch/ + https://nicksxs.me/2016/11/10/php-abstract-class-and-interface/ 2020-01-12T13:08:27.014Z @@ -128,14 +135,14 @@ - https://nicksxs.me/2015/04/14/Add-Two-Number/ + https://nicksxs.me/2015/03/13/Reverse-Integer/ 2020-01-12T13:08:27.012Z - https://nicksxs.me/2015/03/13/Reverse-Integer/ + https://nicksxs.me/2015/04/14/Add-Two-Number/ 2020-01-12T13:08:27.012Z @@ -156,14 +163,14 @@ - https://nicksxs.me/2017/05/09/ambari-summary/ + https://nicksxs.me/2019/06/18/openresty/ 2020-01-12T13:08:27.010Z - https://nicksxs.me/2019/06/18/openresty/ + https://nicksxs.me/2017/05/09/ambari-summary/ 2020-01-12T13:08:27.010Z diff --git a/tags/2019/index.html b/tags/2019/index.html index a93221d0a3..f20a4b4b9d 100644 --- a/tags/2019/index.html +++ b/tags/2019/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/Design-Patterns/index.html b/tags/Design-Patterns/index.html index e0316e3065..21cc1dc399 100644 --- a/tags/Design-Patterns/index.html +++ b/tags/Design-Patterns/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/Distributed-Lock/index.html b/tags/Distributed-Lock/index.html index 89be64c03d..d69124a562 100644 --- a/tags/Distributed-Lock/index.html +++ b/tags/Distributed-Lock/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/G1/index.html b/tags/G1/index.html index c08c744fcb..b226d93596 100644 --- a/tags/G1/index.html +++ b/tags/G1/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/GC/index.html b/tags/GC/index.html index 6cf20238e2..bf4f407a1d 100644 --- a/tags/GC/index.html +++ b/tags/GC/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/Garbage-First-Collector/index.html b/tags/Garbage-First-Collector/index.html index d197296b0c..88ce441392 100644 --- a/tags/Garbage-First-Collector/index.html +++ b/tags/Garbage-First-Collector/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/Gogs/index.html b/tags/Gogs/index.html index 1e1c3fcaa3..a77859b64e 100644 --- a/tags/Gogs/index.html +++ b/tags/Gogs/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/JVM/index.html b/tags/JVM/index.html index ca1846c65a..a205622d80 100644 --- a/tags/JVM/index.html +++ b/tags/JVM/index.html @@ -353,20 +353,20 @@ @@ -391,7 +391,7 @@ diff --git a/tags/Maven/index.html b/tags/Maven/index.html index b091c9f7dd..b89c9b4241 100644 --- a/tags/Maven/index.html +++ b/tags/Maven/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/Redis/index.html b/tags/Redis/index.html index a0ca6e6e43..f3dea39cd3 100644 --- a/tags/Redis/index.html +++ b/tags/Redis/index.html @@ -433,20 +433,20 @@ @@ -471,7 +471,7 @@ diff --git a/tags/Singleton/index.html b/tags/Singleton/index.html index 9755889e90..2c5259ec24 100644 --- a/tags/Singleton/index.html +++ b/tags/Singleton/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/Webhook/index.html b/tags/Webhook/index.html index eb94ff3999..b041a4d40e 100644 --- a/tags/Webhook/index.html +++ b/tags/Webhook/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/aqs/index.html b/tags/aqs/index.html index ea55f95201..6b68370537 100644 --- a/tags/aqs/index.html +++ b/tags/aqs/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/c/index.html b/tags/c/index.html index f68d97bdca..9a83046737 100644 --- a/tags/c/index.html +++ b/tags/c/index.html @@ -516,20 +516,20 @@ @@ -554,7 +554,7 @@ diff --git a/tags/c/page/2/index.html b/tags/c/page/2/index.html index 26827395c7..efc9ba611b 100644 --- a/tags/c/page/2/index.html +++ b/tags/c/page/2/index.html @@ -396,20 +396,20 @@ @@ -434,7 +434,7 @@ diff --git a/tags/cgroup/index.html b/tags/cgroup/index.html new file mode 100644 index 0000000000..14247e46f9 --- /dev/null +++ b/tags/cgroup/index.html @@ -0,0 +1,514 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tag: cgroup | Nicksxs's Blog + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ + +

What hurts more, the pain of hard work or the pain of regret?

+
+ + +
+ + + +
+
+ + +
+ + 0% +
+ + + + +
+
+
+ + +
+ + + + + +
+
+
+

cgroup + Tag +

+
+ + +
+

2020

+
+ + + +
+
+ + + + + + + + +
+ + + + +
+ + + + + + + + +
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/cluster/index.html b/tags/cluster/index.html index 85eb8ddac6..13ac49c780 100644 --- a/tags/cluster/index.html +++ b/tags/cluster/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/docker/index.html b/tags/docker/index.html index 795c3ee4d3..22554ecbf4 100644 --- a/tags/docker/index.html +++ b/tags/docker/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ @@ -512,3 +512,9 @@ +the whole page loading is completed + window.addEventListener('load', loadCount, false); + + + + diff --git a/tags/hadoop/index.html b/tags/hadoop/index.html index b62ebb2e2e..b4c6dd5e27 100644 --- a/tags/hadoop/index.html +++ b/tags/hadoop/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/im/index.html b/tags/im/index.html index 83a8918ab9..81140603a3 100644 --- a/tags/im/index.html +++ b/tags/im/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/index.html b/tags/index.html index b42567ffaa..ac86267907 100644 --- a/tags/index.html +++ b/tags/index.html @@ -249,10 +249,10 @@
@@ -339,20 +339,20 @@ @@ -377,7 +377,7 @@ diff --git a/tags/java/index.html b/tags/java/index.html index 4169f9cd09..a187a89c82 100644 --- a/tags/java/index.html +++ b/tags/java/index.html @@ -57,7 +57,7 @@ - + @@ -68,7 +68,7 @@ - + - Tag: java | Nicksxs's Blog + Tag: Java | Nicksxs's Blog - - - - - - -="/js/motion.js"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tag: namespace | Nicksxs's Blog + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ + +

What hurts more, the pain of hard work or the pain of regret?

+
+ + +
+ + + +
+
+ + +
+ + 0% +
+ + + + +
+
+
+ + +
+ + + + + +
+
+
+

namespace + Tag +

+
+ + +
+

2020

+
+ + + +
+
+ + + + + + + + +
+ + + + +
+ + + + + + + + +
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/nginx/index.html b/tags/nginx/index.html index b689d0a7c1..d4ead79946 100644 --- a/tags/nginx/index.html +++ b/tags/nginx/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/openresty/index.html b/tags/openresty/index.html index ae7f237caf..ab3d237909 100644 --- a/tags/openresty/index.html +++ b/tags/openresty/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/php/index.html b/tags/php/index.html index 53e637cb01..22537e767a 100644 --- a/tags/php/index.html +++ b/tags/php/index.html @@ -353,20 +353,20 @@ @@ -391,7 +391,7 @@ diff --git a/tags/python/index.html b/tags/python/index.html index 776047192a..22127e5374 100644 --- a/tags/python/index.html +++ b/tags/python/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/spark/index.html b/tags/spark/index.html index 7e7475090f..c414d90b3d 100644 --- a/tags/spark/index.html +++ b/tags/spark/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/swoole/index.html b/tags/swoole/index.html index 24c2f7cfe8..64de3576f8 100644 --- a/tags/swoole/index.html +++ b/tags/swoole/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/websocket/index.html b/tags/websocket/index.html index 5f94ce3b09..754df765dc 100644 --- a/tags/websocket/index.html +++ b/tags/websocket/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/分布式锁/index.html b/tags/分布式锁/index.html index ca70217619..6187784ebe 100644 --- a/tags/分布式锁/index.html +++ b/tags/分布式锁/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/单例/index.html b/tags/单例/index.html index 98774ecbe1..4ebcafe670 100644 --- a/tags/单例/index.html +++ b/tags/单例/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/博客,文章/index.html b/tags/博客,文章/index.html index 4ccb178191..89e9246b40 100644 --- a/tags/博客,文章/index.html +++ b/tags/博客,文章/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/寄生虫/index.html b/tags/寄生虫/index.html index b2e303fbbf..b82c92cd17 100644 --- a/tags/寄生虫/index.html +++ b/tags/寄生虫/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/年终总结/index.html b/tags/年终总结/index.html index 32b93e0a5b..fec527ee49 100644 --- a/tags/年终总结/index.html +++ b/tags/年终总结/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/影评/index.html b/tags/影评/index.html index c8fb3cc5cf..850de354d1 100644 --- a/tags/影评/index.html +++ b/tags/影评/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/数据结构/index.html b/tags/数据结构/index.html index 2ee7f5516f..d7f8a15eea 100644 --- a/tags/数据结构/index.html +++ b/tags/数据结构/index.html @@ -433,20 +433,20 @@ @@ -471,7 +471,7 @@ diff --git a/tags/源码/index.html b/tags/源码/index.html index a5bc2b9dd9..6cb116efd3 100644 --- a/tags/源码/index.html +++ b/tags/源码/index.html @@ -433,20 +433,20 @@ @@ -471,7 +471,7 @@ diff --git a/tags/生活/index.html b/tags/生活/index.html index a2474c8c02..16aeef4206 100644 --- a/tags/生活/index.html +++ b/tags/生活/index.html @@ -350,20 +350,20 @@ @@ -388,7 +388,7 @@ diff --git a/tags/设计模式/index.html b/tags/设计模式/index.html index f431ec8c4d..681b64e038 100644 --- a/tags/设计模式/index.html +++ b/tags/设计模式/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@ diff --git a/tags/读后感/index.html b/tags/读后感/index.html index 56ba6b5074..b80bf916fb 100644 --- a/tags/读后感/index.html +++ b/tags/读后感/index.html @@ -330,20 +330,20 @@ @@ -368,7 +368,7 @@