PHP hash_pbkdf2 takes orders of magnitude longer on AWS instances

不羁岁月 提交于 2019-12-11 11:59:10

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/33126113/php-hash-pbkdf2-takes-orders-of-magnitude-longer-on-aws-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!