V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Cloudpods
V2EX  ›  推广

问题分析:为什么 keystone 的本地用户认证接口压测性能很差?

  •  
  •   Cloudpods · 2021-11-17 16:59:46 +08:00 · 994 次点击
    这是一个创建于 912 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有用户反馈 keystone 认证本地用户的接口性能很差,因此做了调研。

    首先使用 ab ( apache benchmark )模拟用户认证,调用命令行如下:

    ab -n 2000 -c 100 -p ~/auth_body.json -T 'application/json' http://192.168.1.248:5000/v3/auth/tokens
    

    执行以上脚本过程中,采集 keystone 的 pprof 的 profile 数据:

    wget http://192.168.1.248:5000/debug/pprof/profile
    

    然后把 profile 数据文件拷贝到本地,用本地 go tool 打开一个 http 服务,查看 profile 的内容。

    go tool pprof -http=0.0.0.0:8081 ~/profile
    

    用浏览打开看,得到如下的调用图:

    发现整个 profile 时间约 130 秒,调用 blowfish encryptBlock 的时间花了约 101 秒。查看代码发现这个是密码校验调用的方法 bcrypt.CompareHashAndPassword 。也就是说,70%的时间都花在验证本地用户的密码上了。

    为什么这个 bcrypt.CompareHashAndPassword 方法这么慢呢?搜索 google 发现这个问答:

    https://stackoverflow.com/questions/49437359/why-bcrypt-library-comparehashandpassword-method-is-slow

    其中有一段文字:

    Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with increasing computation power.
    

    因此,采用 bcrypt 加密用户密码后,为了防止密码被暴力破解,用户认证接口的校验速度是故意地越压越慢的,性能必然不会好。

    作者: 云联壹云邱剑

    GitHub: https://github.com/yunionio/cloudpods

    开源地址: https://www.cloudpods.org/

    Cloudpods 是一个开源的 Golang 实现的云原生的多云和混合云融合平台。Cloudpods 不仅可以管理本地的虚拟机和物理机资源,还可以管理其他公有云和私有云平台的资源。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2298 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 01:29 · PVG 09:29 · LAX 18:29 · JFK 21:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.