我想用 rados 的 object 存储文件,用 LockShared 和 LockExclusive 实现了一个读写锁 但当我测速时发现 LockShared 性能好低啊,每秒 20 个,我以为只是延迟高,但发现并发也没用
func newConn() *rados.Conn {
conn, err := rados.NewConn()
if err != nil {
panic(err)
}
cephInitByFile(conn, "k8s_conf")
err = conn.Connect()
if err != nil {
panic(err)
}
return conn
}
func init() {
conn = newConn()
}
func TestConcurrencyLockShared(t *testing.T) {
// open a pool handle
oid := "concurrency_lock_shared"
oidLock := "lock"
maxExpired := time.Minute
times := 100
wg := sync.WaitGroup{}
wg.Add(times)
for i := 0; i < times; i++ {
go func(i int) {
defer wg.Done()
ioctx, err := conn.OpenIOContext(poolName)
require.NoError(t, err)
res, err := ioctx.LockShared(oid, oidLock, "cookie"+fmt.Sprint(i), "", "lock test", maxExpired, nil)
assert.NoError(t, err)
assert.Equal(t, 0, res)
}(i)
}
wg.Wait()
wg.Add(times)
for i := 0; i < times; i++ {
go func(i int) {
defer wg.Done()
ioctx, err := conn.OpenIOContext(poolName)
require.NoError(t, err)
res, err := ioctx.Unlock(oid, oidLock, "cookie"+fmt.Sprint(i))
assert.NoError(t, err)
assert.Equal(t, 0, res)
}(i)
}
wg.Wait()
}
1
bigpigeon OP 捞一下,有大佬知道原因吗
|