V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
bigpigeon
V2EX  ›  Linux

go-cpeh 的中 LockShared 性能好差啊

  •  
  •   bigpigeon · 2019-09-23 15:15:03 +08:00 · 2475 次点击
    这是一个创建于 1649 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我想用 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 条回复    2019-09-24 10:39:04 +08:00
    bigpigeon
        1
    bigpigeon  
    OP
       2019-09-24 10:39:04 +08:00
    捞一下,有大佬知道原因吗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3305 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 10:46 · PVG 18:46 · LAX 03:46 · JFK 06:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.