PHP hash_pbkdf2在AWS实例上的等级更长 [英] PHP hash_pbkdf2 takes orders of magnitude longer on AWS instances
问题描述
我们想要在PHP中对hash_pbkdf2函数进行基准测试,为应用程序选择适当的迭代次数。
当我在m4上运行我的基准测试脚本时。大AWS实例,运行比我的笔记本电脑长了五个数量级。
这个Gist显示我使用的脚本,我得到的结果一个m4.large实例(负载下),一个t2.micro实例(具有完全的CPU信用和无负载)和三个不同速度的Intel i7笔记本电脑。
https://gist.github.com/roberthl/301a3fb0a32baf057806
您可以在i7笔记本电脑上看到100,000次迭代所需时间<200ms,但只需要一次迭代就可以在AWS实例上花费这么长时间。
包括PHP版本和OpenSSL基准,显示sha256在AWS实例和i7笔记本电脑上花费相当长的时间(而且PHP散列函数的基本基准也显示了这一点),这表明它特别与PBKDF2相关
是什么原因导致这种情况发生? / div>
请注意,AWS实例正在使用GIST中所有内容的最早的PHP版本。这不可能是伟大的。
如果可以,找到一个最近年份的可移植PHP产品,然后安装并进行基准测试。
此外,您可以从我的Github存储库,包括基于PolarSSL,OpenSSL和Crypto ++的版本,都具有相同的命令行和源代码接口。
We wanted to benchmark the hash_pbkdf2 function in PHP to select an appropriate number of iterations for our application to use.
When I ran my benchmark script on an m4.large AWS instance, it took five orders of magnitude longer to run than it does on my laptop.
This Gist shows the script I am using, and the results I get from an m4.large instance (under load), a t2.micro instance (with full CPU credits and no load) and three different speed Intel i7 laptops.
https://gist.github.com/roberthl/301a3fb0a32baf057806
You can see the 100,000 iterations take <200ms on the i7 laptops, but just a single iteration takes that long on the AWS instances.
I've included the PHP versions, and an OpenSSL benchmark that shows sha256 taking a comparable amount of time on both the AWS instances and an i7 laptop (and a rudimentary benchmark of the PHP hash function also showed this) - suggesting it is specifically related to the PBKDF2 operation.
What causes this to happen, and how can I speed it up?
Note that the AWS instances are using the oldest PHP version of everything in your GIST. That can't be great.
If you can, find a Portable PHP product of recent vintage and install and benchmark it instead.
Additionally, you can benchmark a variety of PBKDF2 implementations from my Github repository, including PolarSSL, OpenSSL, and Crypto++ based versions, all with identical interfaces for the command line and source code.
这篇关于PHP hash_pbkdf2在AWS实例上的等级更长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!