DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

战战兢兢

如履薄冰

重回苦行僧般的生活


本周:

  • 完成第一版的脚本的提交
  • 框架部分完成大概

下周:

  • 完成多表拼接的具体任务
  • 脚本的修改以及集成

不断地降低自己的预期和奢望,不断地远离自己的舒适区,保持谦卑的心态和想法,重回苦行僧般的生活。。。

所谓苦行僧,也就是按部就班,努力地践行着那种愚笨的方法和计划,这样,不管是在得到或者失去的时候,不至于有大喜大悲,不放纵,也不过度地丧,得之我幸,失之我命,佛与道的无为和平淡。。。

锻炼计划,慢慢恢复,每周的keep部分也要坚持下去,跑步什么的,也要持续下去,腰围和腿围要降下去。。。

生活上,时间计划安排上,还要进一步把控,答应的事情,一定要做到一些,按照自己的标准和原则,去做些所谓心安的事情吧。。。

读书上,要慢慢捡起来,每个月1本书的习惯,要努力践行起来。。。

原文链接

主要是介绍没有泛型的情况下,hashmap实现上的一些高效考虑

Go’s map is a hashmap

hash function

  • The first is stability. The hash function must be stable. Given the same key, your hash function must return the same answer
  • The second property is good distribution. Given two near identical keys, the result should be wildly different

In this case our hashmap has eight buckets (as this is the value that the Go implementation uses) and each bucket can hold up to eight entries each (again drawn from the Go implementation)

insert process

a hash map four properties

  1. You need a hash function for the key.
  2. You need an equality function to compare keys.
  3. You need to know the size of the key and,
  4. You need to know the size of the value because these affect the size of the bucket structure, which the compiler needs to know, as you walk or insert into that structure, how far to advance in memory.

java

boxing: boolean, int, short, long, byte, char, float, and double to java.lang.Object

c++同java实现hashmap的优缺点

c++
  • key和value的大小,在compile阶段就知道
  • 可以进行inlineing
  • 速度快
  • 编译和代码上慢,要有不同的types
java
  • 天然有泛型的含义,一切都是object
  • 同样也是缺点,boxing等方式,会增大gc的概率
  • Buckets are stored as linked lists, not sequential arrays

golang的实现

While we have the container/{list,heap} packages which do use the empty interface, the runtime’s map implementation does not use interface{}.

1
2
3
4
v := m["key"]     → runtime.mapaccess1(m, ”key", &v)
v, ok := m["key"] → runtime.mapaccess2(m, ”key”, &v, &ok)
m["key"] = 9001 → runtime.mapinsert(m, ”key", 9001)
delete(m, "key") → runtime.mapdelete(m, “key”)

实际上针对channel的操作?

1
func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer

在mapaccess中,指明maptype,不同于c++部分针对所有的map有不同的实现,golang部分,在compile阶段生成maptype字段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
type maptype struct {
typ _type
key *_type
elem *_type
bucket *_type // internal type representing a hash bucket
hmap *_type // internal type representing a hmap
keysize uint8 // size of key slot
indirectkey bool // store ptr to key instead of key itself
valuesize uint8 // size of value slot
indirectvalue bool // store ptr to value instead of value itself
bucketsize uint16 // size of bucket
reflexivekey bool // true if k==k for all keys
needkeyupdate bool // true if we need to update key on overwrite
}

mapaccess的功能如下:

1
2
3
4
5
6
7
8
9
10
11
// mapaccess1 returns a pointer to h[key].  Never returns nil, instead
// it will return a reference to the zero object for the value type if
// the key is not in the map.
func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {

if h == nil || h.count == 0 {
return unsafe.Pointer(&zeroVal[0])

}
alg := t.key.alg
hash := alg.hash(key, uintptr(h.hash0))
m := bucketMask(h.B)
b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))

同样是走过新美的三年,最后的选择,也算是应验了三年前戏言的一句,跟着瀚总干。

不过,感觉还是自己有点想简单了,就算你是面向工资编程,但是新环境,新技术,新的人,带来的冲击还是很大。。。开始变得有点患得患失,对自己的焦虑,对自己的失望等等。。。

算是莫名其妙地开启这一段新的旅程,同样的,感觉自己的发展方向又变了,幸好自己还有一些java的底子,还不算太差

不管那些有的没的负面情绪,以自己为主,去学习,去了解,希望自己能在这段旅程收获一些东西

  • 发现新的领域,并能做出一些东西/成绩出来
  • 规划自己的人生,不管是工作还是生活,想清楚自己的方向
  • 养成一些好的习惯,戒掉自己的拖延症以及一些其他坏的习惯
  • 拓宽自己的视野,坚守自己的原则以及信念

其实,这些想法跟3年前并没有什么不同,就像之前说的那样,旅程上,去见一些人,一些事,做一些事,学一些东西,仅此而已,旅程就也够了

现在很大的一个问题,还是想的太多,做的还不够,写的不够多,锻炼的不够,有实际的想的不够,总结的不够,学习的不够。。。

领域方面:

  • 业务上,总结一些框架出来,对于系统部分的一些剥离和重构
  • 机器学习的算法上,各种算法的学习和深入
  • 内部工具效率方面,能够工具化自己的日常工作,去不断地提升效率
  • 多写wiki,多写总结,多写想法

规划方面:

  • 生活上,通过去学习身边人的想法,学习书本以及视频中的想法,去设想自己未来想要的生活

习惯上:

  • 通过每周一总结,去努力地克服掉自己的拖延症,通过贴一些小纸条,来强化自己要做的事情

视野上:

  • 接触各种不同的东西,敢于去改变,去接触,去了解不同的事物,改变自己的心态

其实,也不知道自己这段旅程能坚持多久,说不定还过不了试用期。。哈哈。。。

要懂得和同事保持距离。要明白你对大多数人来说,只是大多数人之间的一个。你并没有什么特殊的。。。

但不管怎么样,踏踏实实地走好每一步,也算是经历过,也没啥,放轻松心态。。。

日剧<<火花>>

只要还活着

就不会有坏结局

我们仍然在故事的中途


本周工作:

  • 基本完成增量DAG改造的框架
  • 模板的导入与导出功能,相关项目开始上手入门

本周所得:

  • 手把手教k8s的搭建部分

下周工作:

  • 串联自动拼表的功能
  • 部署环境部分的梳理

保持学习的心态,保持谦卑,不要把以前的经验总放在心上,当成一碗白水,重新去适应新的环境,新的文化。。。

可能是自己习惯了单打独斗,对于协同部分,不是很适应,其实,所谓的做架构,其实就是做人的分配,以及活的分配,可能自己还是达不到这个水平吧,或者说,有点不适应搞这个,达不到所谓的预期吧。。。

可能还是不适合干这个打交道的事情吧,自己尽量去做,尽量去想吧,至于能不能达到,也不是自己能说清楚的,也没什么大不了的,顶多就是失败了,失败也没什么可怕的,就当是学习/体验一趟,做好心理准备就好了。。。

你在害怕什么?失败?达不到别人的预期的失望?自己的失望?不过是自己不行的接口罢了。。

保持输出,不管自己的理解是什么样子的,保证一定的wiki或者blog的编写,对自己的理解以及学习上有更大的帮助。。。

只要活着,就还在编写故事,不管是好的,还是坏的,都是在体验人生的一部分。。。无畏失败,尽量去体验,尝试就可以了,没什么好失去的,静静地做好自己就好了,尽自己最大的努力去活着,其他的就管不了。。

锻炼上,开始慢慢恢复,晚上增加keep的选项,保证一定量的运动?

人一过三十,十二点就变得很困。。。将一些时间点移到早上,在早上进行学习等等。。。

为自己的行为负责,孤独地活下去。。。

视频地址

主要是介绍weave cloud中k8s的一些实践部分

building containers

clair, 对镜像的静态分析

use the build pattern

build container -> build artifact -> runtime container

在镜像中,尽量使用非root用户?yaml中有相应的选项

One process per container

pod运行所有的process

Don’t restart on failure. Crash cleanly instead

举的例子就是PM2运行nodejs程序,k8s会重启container,只需要返回更高的code让k8s去检测到

log to stdout and stderr

Deployments

记录每次deploy的record部分

关于label的使用

Use sidecar containers for proxies, watchers, etc

程序只需要跟本地的端口部分打交道,由proxy去同其他部分,进行auth,rate,limiting等等相关的交互

Don’t use sidecars for bootstarpping. Just use initial container instead

Don’t use :latest or no tag

Health check

  • Readiness->是否已经启动,并接收流量
  • Liveness->是否还在运行

Services

type: NodePort can be “good enough”

map external services to internal ones

内部一个点,外部一个点,从而避免内外部混用,配置文件部分也不同

Use Helm Charts

Just assume that all your downstream dependencies are unreliable

Use a “Service Mesh”

istio 或者linkerd部分?可以无缝接到你的container部分

Use Namespaces to split up your cluster

Unleash the chaos monkey

?

Challenges on K8s Cluster

Infrastructure的版本控制

Terraform to configure infrastructure

Kubediff

Continuous Delivery

branch and commit Id in the image tag

一个工具flux

###关于报警和监控部分

使用k8s的服务发现,tsdb部分的存储,pull vs push