tech
Go 1.24: New STD-lib synctest
Go 1.24 introduces `testing/synctest`, enhancing concurrent testing by using virtual clocks for faster, reliable results. #Golang #Testing
tech
Go 1.24 introduces `testing/synctest`, enhancing concurrent testing by using virtual clocks for faster, reliable results. #Golang #Testing
tech
Go 1.24 引入了 `testing/synctest`,利用虚拟时钟简化了并发代码测试,从而实现更快、更可靠的测试!🚀 #GoLang #测试
tech
Previously, I wrote an article about the runtime.SetFinalizer that is used to be called when an object is cleaned up, but some issues with this function cause it to be used less frequently. https://github.com/golang/go/issues/67535 * SetFinalizer must always refer to the first word of
tech
Golang 1.24 introduces `runtime.AddCleanup`, improving upon `runtime.SetFinalizer` by allowing multiple cleanup functions and better handling of object references, thus preventing memory leaks and enabling timely cleanup. #Golang #Go1_24
tech
Golang 1.24 introduces `os.Root`, enhancing file safety by limiting access to specified directories. This prevents directory traversal vulnerabilities. #GoLang #osRoot
tech
Golang 1.24 引入了 `os.Root`,通过防止目录遍历攻击来增强文件操作的安全性。它确保操作仅限于指定目录。#Golang #安全性 #osRoot
tech
Understanding BigCache and Its Optimization Strategies
tech
bigcache是一个高性能的内存缓存库,专为需要高并发访问和低延迟响应的应用场景设计。本文将深入探讨 BigCache 的性能优化手段,包括分片机制、高效哈希算法、读写锁的使用等,并引用相关源码进行详细说明。 分段加锁 从使用者的角度来看cache就像一个大的hashtable,可以存储k/v 格式的数据。 那么,是不是可以使用一个map[string][]byte + sync.RWMutex 实现满足需求的cache呢? 如果性能要求不高,的确可以这么做。 sync.RWMutex虽然对读写进行了优化,但是对于并发的读,最终还是把写变成了串行,一旦写的并发量大的时候,即使写不同的key, 对应的goroutine也会block,只允许一个写执行,这是一个瓶颈,并且不可控。 bigcache 参考了 java ConcurrentMap 的实现方式,将一个大hashtable 分成多个小的 shard,每个分片一把锁,很多大并发场景下为了减小并发的压力都会采用这种方法,比如MongoDB的sharding等。Golang也有一个第三方的 ConcurrentMap
tech
Understanding the Essence of Lock-Free Programming
tech
对于无锁编程来讲,无锁只是一个表象,编程者设法组织 data+processing,重点在于如何消除 dataracing。而消除 dataracing 而言,传统的并发编程逻辑是采用关键区、排他性锁、读写锁等方式来保护 data 不会因为 processing 而导致错误读或错误写,那么对于无锁编程来说,则是通过消除 data 的共享性,或者消除并发操作 data 等方式来解决问题。 所以最典型的无锁编程技法包含两个技巧: 1. structure 2. bumper loop 其他的方法都是相似思路的具体衍生。 这里的“其他的方法”,是指完全不使用锁定或 CAS 的算法设计方案。本文中讨论的是如何设计数据结构及其处理器(算法)来防止加锁,甚至于连 CAS 也去除。 至于在共享的data上强行消除竞争读写问题的其他无锁方案,例如RingBuffer之类的工具类库,则是完全依赖于具体的 data 实体并在具体的 CPU 上进行设计,基本上是一种很受限的方法,
tech
Will it become the standard library for go maps?
tech
Performance Implications of Memory Escaping in Go Programming