• Soft Hard Limit In Linux

    https://docs.oracle.com/cd/E19455-01/805-7229/6j6q8svfe/index.html

    You can set both soft and hard limits. The system will not allow a user to exceed his or her hard limit. However, a system administrator may set a soft limit (sometimes referred to as a quota) which can be temporarily exceeded by the user. The soft limit must be less than the hard limit.

    Once the user exceeds the soft limit, a timer begins. While the timer is ticking, the user is allowed to operate above the soft limit but cannot exceed the hard limit. Once the user goes below the soft limit, the timer gets reset. However, if the user’s usage remains above the soft limit when the timer expires, the soft limit is enforced as a hard limit. By default, the soft limit timer is seven days.

    The value of the timer is shown by the timeleft field in the repquota and quota commands.

    For example, let’s say a user has a soft limit of 10,000 blocks and a hard limit of 12,000 blocks. If the user’s block usage exceeds 10,000 blocks and the timer is also exceeded (more than seven days), the user will not be able to allocate more disk blocks on that file system until his or her usage drops below the soft limit.

  • Core

    core(5) — Linux manual page

    官方手册里面讲了 core dump 的一些配置和行为特征,简单总结一下。

    1. 什么情况下,不会生成 core dump。
    2. core dump 的名字配置 /proc/sys/kernel/core_pattern 主要通过这个配置 /proc/sys/kernel/core_uses_pid 一个更基础(更简单?)的配置 但这里有些疑惑,如果 pattern 不是用的默认值,那 used_pid 是不是还生效呢?
    3. 将 core 文件管道到另外的程序
    4. 哪些 mapping 可以被写到 dump 文件
    5. 使用 systemd 做管道以及相应的配置和操作

    注1 针对第二点测试了一下,如果 pattern 里面使用了变量,就会忽略 used_pid,如果没有使用变量,就会使用 pattern 中的配置+used_pid

  • Linux Memory Contoller

    Memory Resource Controller - The Linux Kernel documentation

    Each cgroup maintains a per cgroup LRU which has the same structure as global VM. When a cgroup goes over its limit, we first try to reclaim memory from the cgroup so as to make space for the new pages that the cgroup has touched. If the reclaim is unsuccessful, an OOM routine is invoked to select and kill the bulkiest task in the cgroup. (See 10. OOM Control below.)

    OOM Control¶

    memory.oom_control file is for OOM notification and other controls.

    Memory cgroup implements OOM notifier using the cgroup notification API (See Control Groups). It allows to register multiple OOM notification delivery and gets notification when OOM happens.

    To register a notifier, an application must:

    create an eventfd using eventfd(2)

    open memory.oom_control file

    write string like “ ” to cgroup.event_control

    The application will be notified through eventfd when OOM happens. OOM notification doesn’t work for the root cgroup.

    You can disable the OOM-killer by writing “1” to memory.oom_control file, as:

    #echo 1 > memory.oom_control

    If OOM-killer is disabled, tasks under cgroup will hang/sleep in memory cgroup’s OOM-waitqueue when they request accountable memory.

    For running them, you have to relax the memory cgroup’s OOM status by

    enlarge limit or reduce usage.

    To reduce usage,

    kill some tasks.

    move some tasks to other group with account migration.

    remove some files (on tmpfs?)

    Then, stopped tasks will work again.

    At reading, current status of OOM is shown.

    oom_kill_disable 0 or 1 (if 1, oom-killer is disabled)

    under_oom 0 or 1 (if 1, the memory cgroup is under OOM, tasks may be stopped.)

    oom_kill integer counter The number of processes belonging to this cgroup killed by any kind of OOM killer.

  • Sb

    你怎么傻逼都行,但请不要连累我。

  • Kafka Healer

    https://programmer.group/kafka-golang-client-introduction.html

    看到一篇文章,里面有一点点提到了 healer,这介绍还真的是非常准确。

    Client name	Advantages and disadvantages
    sarama	The number of users is relatively large, but it is relatively difficult to use, with better performance
    confluent-kafka-go	The encapsulation of Kafka in C language has strong performance, but depends on librdkafka
    kafka-go	The operation is simple, but the performance is poor. The common dual core CPU machine in the production environment only processes about 300 pieces per second
    healer	The operation is very simple, and the performance is similar to that of sarama. This product is the work of a big bull of Ctrip. At present, the number of users in the community is small, and there is no corresponding support and maintenance
    
  • jsonpath 里面的转义

    如果一个字段名字带点,可以这样转义

    kd get pod -n redis 808098-2 -o jsonpath="{['metadata']['labels']['statefulset\.kubernetes\.io/pod-name']}"
    

    如果要输出换行要:

    kd get pod -n redis 808098-2 -o jsonpath="{['metadata']['labels']['statefulset\.kubernetes\.io/pod-name']} {'\n'}"
    
  • Write String To Stdout Benchmark

    使用 os.Stdout.Write 并不比 fmt.Println 快,甚至还慢了一点点儿。

  • 没有Accept的Socket是不是显示在ESTABLISHED

    在 MACOS 测试,会显示。

    import socket
    import time
    
    HOST = ""  # Symbolic name meaning all available interfaces
    PORT = 50007  # Arbitrary non-privileged port
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind((HOST, PORT))
        s.listen(1)
        time.sleep(10)
        conn, addr = s.accept()
        with conn:
            print("Connected by", addr)
            while True:
                data = conn.recv(1024)
                if not data:
                    break
                conn.sendall(data)
    
  • Sb

    萌和傻逼是绝对对立的,如果一个行为傻逼,那绝对就不会是萌。

  • Slice Thread Safe Test

    package main
    
    func main() {
    	arr := make([]int, 0)
    	go func() {
    		for i := range arr {
    			print(i)
    		}
    	}()
    
    	go func() {
    		for i := 0; i < 10; i++ {
    			arr = append(arr, i)
    		}
    	}()
    }
    

    测试结果

    go run -race main.go
    ==================
    WARNING: DATA RACE
    Write at 0x00c00009e000 by goroutine 7:
      main.main.func2()
          /Users/liujia/tmp/1655653776/main.go:13 +0xcb
    
    Previous read at 0x00c00009e000 by goroutine 6:
      main.main.func1()
          /Users/liujia/tmp/1655653776/main.go:6 +0x30
    
    Goroutine 7 (running) created at:
      main.main()
          /Users/liujia/tmp/1655653776/main.go:11 +0x14e
    
    Goroutine 6 (finished) created at:
      main.main()
          /Users/liujia/tmp/1655653776/main.go:5 +0xe4
    ==================
    Found 1 data race(s)
    exit status 66