Jun

Results 164 comments of Jun

# 0x03 栈帧的获取 可以通过`sys._getframe`获取当前的`PyFrameObject`对象。 ```python >>> import sys >>> frame = sys._getframe() >>> frame ```

@jiajunhuang 嗯,看了有一段时间了

@ttop5 Docker 可以用來做一些好玩的東西哈,很早就想嘗試 Mysql 的主從複製,Docker上操作更方便。

# SecureServingInfo SecureServingInfo 在 apiserver 中的作用与 http.ListenAndServe 类似。 ```go // pkg/server/deprecated_insecure_serving.go type SecureServingInfo struct { // Listener is the secure server network listener. Listener net.Listener // Cert is the main...

# Config / CompletedConfig Config 作为 apiserver 的配置结构: ```go // pkg/server/config.go // Config is a structure used to configure a GenericAPIServer. // Its members are sorted roughly in order of...

# GenericAPIServer GenericAPIServer 是 apiserver 提供服务的结构体,维护 apiserver 的状态。 ```go // pkg/server/genericapiserver.go // GenericAPIServer contains state for a Kubernetes cluster api server. type GenericAPIServer struct { ... // Handler holds the...

![image](https://user-images.githubusercontent.com/8097526/81478015-5ab26800-924d-11ea-8782-05c85d4dae56.png)

到这里可以利用 SecureServingInfo 和 APIServerHandler 来启动服务处理请求。 完整的 demo 代码见 [gist](https://gist.github.com/Junnplus/49dec126a14ae9381690428340e4666a) ```js # curl -k https://127.0.0.1:6443 { "paths": [ "/apis", "/metrics" ] } ``` GenericAPIServer 还提供了 PrepareRun 的方法来启动 API 安装,通过封装的 preparedGenericAPIServer.Run() 来启动服务。...

## pool 内存池 (pool的管理) 在实际的使用中,Python并不直接与arenas和arena打交道。当Python申请内存时,最基本的操作单元并不是arena,而是pool。 我们知道block是Python中内存分配的最小单位,而block是由pool来管理的,pool是一个有size概念的内存管理抽象体,一个pool中的block总是有确定的大小。因此,要找到与所申请的大小相对应的block,需要先找到有这个block的pool。 Python中为了实现快速搜索对应block大小的pool,维护了一个`usedpools`的数组。在了解`usedpools`数组之前,我们得先提以下pool的三种状态: - used状态,pool中部分block被使用,这种状态的pool受控`usedpools`数组; - full状态,pool中所有的block都被使用; - empty状态,pool中所有的block都未被使用,处于这个状态的pool的集合通过`pool_header`中的`nextpool`构成单向链表,这个链表的表头就是`arena_object`中的`freepools`。 arena包含的三种状态pool的表示: ![image](https://user-images.githubusercontent.com/8097526/35693861-790437ae-07ba-11e8-8b90-6edb22b3745f.png) 那么`usedpools`是怎么和pool联系起来呢? 当申请内存时,申请的大小会对应到一个size class index,就是通过索引将`usedpools`和pool联系起来的。 ![image](https://user-images.githubusercontent.com/8097526/35696826-75e1531e-07c3-11e8-9fa1-b24c5c096106.png) `usedpools`的每个size class index都会对应一个`pool_header`指针,每个pool用双向链表相连,形成一个循环双向链表。 我们来看下`usedpools`的定义: ```c static poolp usedpools[2 * ((NB_SMALL_SIZE_CLASSES...

#### 内存池全景: ![image](https://user-images.githubusercontent.com/8097526/36831884-4f0471d4-1d64-11e8-84ab-850dd52a34a9.png)