青蛙小白
#Linux

Linux的进程状态

进程的状态 进程是Linux系统结构的基础,进程简单的理解就是一段程序的执行过程。系统的每一个进程会有不同的状态。 Linux源码中对进程状态的定义fs/proc/array.c: static const char * const task_state_array[] = { "R (running)", /* 0 */ "S (sleeping)", /* 1 */ "D (disk sleep)", /* 2 */ "T (stopped)", /* 4 */ "t (tracing stop)", /* 8 */ "X (dead)", /* 16 */ "Z (zombie)", /* 32 */ }; 系统进程状态包括:

#Go

Golang 1.7 GC的简单理解

从Go 1.7 runtime包理解Golang GC Go也是垃圾回收的,实现方式和别的语言不太一样。 先从Go的标准库的runtime包说起,这个包有很多运行时相关的类型和函数。 调用runtimea.GC()可以触发GC,但我们一般不会这么做,先读一下这个函数的注释说明。 GC runs a garbage collection and blocks the caller until the garbage collection is complete. It may also block the entire program 大概的意思是,Go的GC触发时会阻塞整个程序的运行。这个在垃圾回收里面有一个比较有名的名词叫STW,Stop the World。就是说程序在GC时“整个世界会停止下来”。 Go垃圾回收的STW一直是Go语言被指责和诟病最多的地方,也是Go的每个版本都努力改进的地方。

#Mysql

MySQL Server的日志

MySQL日志类型 错误日志(Error log): mysqld启动,运行,停止相关的警告或错误信息 普通查询日志(General query log): 记录从连接客户端发出的SQL语句和MySQL命令 二进制日志(Binary log): 对数据库执行更新的语句,二进制日志也被用来在主从复制时使用 中继日志(Relay log): 主库推送的主库二进制日志中的事件到从库的中继日志,从库根据中继日志重做数据变更操作 慢查询日志(Slow query log): 执行时间超过long_query_time设定值的SQL语句,也可包含没有使用索引的SQL语句 DDL log (metadata log): Metadata operations performed by DDL statements 错误日志 MySQL的错误日志是默认开启,且必须开启。查看错误日志的位置:

#Go

从源码理解Go:map

map的内部结构 Go中的map使用哈希表实现的,在源码go runtime/hashmap.go中可以看到对应实现。 // A header for a Go map. type hmap struct { // Note: the format of the Hmap is encoded in ../../cmd/internal/gc/reflect.go and // ../reflect/type.go. Don't change this structure without also changing that code! count int // # live cells == size of map. Must be first (used by len() builtin) flags uint8 B uint8 // log_2 of # of buckets (can hold up to loadFactor * 2^B items) noverflow uint16 // approximate number of overflow buckets; see incrnoverflow for details hash0 uint32 // hash seed buckets unsafe.Pointer // array of 2^B Buckets. may be nil if count==0. oldbuckets unsafe.Pointer // previous bucket array of half the size, non-nil only when growing nevacuate uintptr // progress counter for evacuation (buckets less than this have been evacuated) // If both key and value do not contain pointers and are inline, then we mark bucket // type as containing no pointers. This avoids scanning such maps. // However, bmap.overflow is a pointer. In order to keep overflow buckets // alive, we store pointers to all overflow buckets in hmap.overflow. // Overflow is used only if key and value do not contain pointers. // overflow[0] contains overflow buckets for hmap.buckets. // overflow[1] contains overflow buckets for hmap.oldbuckets. // The first indirection allows us to reduce static size of hmap. // The second indirection allows to store a pointer to the slice in hiter. overflow *[2]*[]*bmap } // A bucket for a Go map. type bmap struct { // tophash generally contains the top byte of the hash value // for each key in this bucket. If tophash[0] < minTopHash, // tophash[0] is a bucket evacuation state instead. tophash [bucketCnt]uint8 // Followed by bucketCnt keys and then bucketCnt values. // NOTE: packing all the keys together and then all the values together makes the // code a bit more complicated than alternating key/value/key/value/... but it allows // us to eliminate padding which would be needed for, e.g., map[int64]int8. // Followed by an overflow pointer. } 先删掉代码原有注释,以便于查看: