HTTP Basic Auth、读取密码文件和性能
我很想知道在 Apache、lighttpd 或 nginx 等网络服务器上使用 HTTP 基本身份验证对性能有何影响。我想瓶颈是服务器实际读取文件以验证用户身份。在我看来,读取文件以验证用户身份的成本与该文件中的用户数量成正比。
我的问题是:
1. 是否存在特定数量的用户,通过文件进行的基本身份验证开始急剧下降,或者与文件中的用户数量成线性关系?
2. 鉴于 http 的无状态特性,如果 Web 服务器已针对一个请求使用 HTTP Basic Auth 对用户进行了身份验证:
- 它是否只是转发每个请求的凭据,并且网络服务器每次都必须解析密码文件以确定这是否是来自有效用户的请求?
或
- 获取类似令牌之类的东西,在后续请求的 http 标头中使用,从而允许服务器避免再次解析密码文件?
提前致谢
I'm curious to know what are the performance impacts of using HTTP Basic Auth on a webserver like Apache or lighttpd or nginx. I imagine the bottleneck is the actual reading of the file by the server to authenticate a user. It also seems to me that the cost of reading the file to authenticate a user is proportional to the number of users in that file.
Questions i have are:
1. is there a specific number of users at which basic auth via file starts to fall dramatically or is it linearly relative to the number of users in the file?
2. Given the stateless nature of http, if a user has been authenticated using HTTP Basic Auth by the webserver on one request:
- does it simply forward the credentials on every request and the webserver must parse the password file everytime in order to determine if this is a request from a valid user?
or
- get something like a token that it uses in the http header on subsequent requests, allowing the server to avoid parsing the password file again?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
线性相对。我不会担心。 HTTP Basic Auth 被证明是可扩展的。仅以 Twitter API 为例。它使用Basic Auth。
“由于 HTTP 协议是无状态的,因此即使来自同一客户端,每个请求也会以相同的方式处理。也就是说,从服务器请求的每个资源都必须在幸运的是,浏览器会处理此处的详细信息,因此您只需在每个浏览器会话中输入一次用户名和密码 - 也就是说,您下次可能需要再次输入。打开浏览器并访问同一网站。”
详细信息请参见 Apache Auth 文档。
Linearly relative. I wouldn't worry. HTTP Basic Auth is proved to be scalable. Just take the Twitter API as an example. It uses Basic Auth.
Detailed info in the Apache Auth documentation.
我的经验仅限于 Apache 2.x。
ap_cfg_getline()
因此它将与行数(用户)呈线性关系。My experience is with Apache 2.x only.
ap_cfg_getline()
so it will be linear to number of lines (users).无论有多少用户,在登录时解析一次文件应该可以很好地扩展。我真的不会担心这个。将来,您可以开发具有适当索引的数据库驱动方法。我怀疑您在开发网站时会遇到的所有瓶颈,基本身份验证在很长一段时间内都不会成为其中之一 - 除非您的网络服务器动力严重不足。
Parsing a file once at logon should scale pretty well, no matter how many users there are. I really wouldn't worry about it. In the future, you can develop a database driven approach with proper indexing. I suspect of all the bottlenecks you'll be running into developing a site, Basic Auth isn't going to be one of them for a very very long time - unless your webserver is VASTLY underpowered.