We use Bcrypt hash to encrypt user's password. One of the strength of bcrypt is that its inherently slow to compute the hash and that makes the brute force breaking of password almost impossible. But I recently ran into an interesting issue where almost overnight the build times on jenkins blow up from 12 mins to 22 mins and the build engineer complained about bulk user testcase as the culprit.
I ran it locally and found that the class had close to 15 tests and each test method was taking 20 sec and all I see is in setup we were creating 5 users and deleting 5 users in teardown. So as usual best way to debug a performance problem is to look at the thread dump. I did a ps -ef on the running build and did a kill -QUIT to print the thread dump and immediately I saw time spent in Bcrypt computation. I took 3-4 more thread dump and all of them were stuck on bcrypt. So I did two things:
1) I saw many methods in the test class that were testing pure validations and didnt needed the creation/deletion of users. So I moved them to a new Unit test class.
2) I added a JVM property to skip Bcrypt computation during user creation and passed that as a jvm argument to ant test target. This is to prevent not the skip in the prod environment.
And voila the build times were back to 13 mins.
I ran it locally and found that the class had close to 15 tests and each test method was taking 20 sec and all I see is in setup we were creating 5 users and deleting 5 users in teardown. So as usual best way to debug a performance problem is to look at the thread dump. I did a ps -ef on the running build and did a kill -QUIT to print the thread dump and immediately I saw time spent in Bcrypt computation. I took 3-4 more thread dump and all of them were stuck on bcrypt. So I did two things:
1) I saw many methods in the test class that were testing pure validations and didnt needed the creation/deletion of users. So I moved them to a new Unit test class.
2) I added a JVM property to skip Bcrypt computation during user creation and passed that as a jvm argument to ant test target. This is to prevent not the skip in the prod environment.
And voila the build times were back to 13 mins.
Comments
Post a Comment