-1

My spring OAuth2.0 authorization micrservice is extremely slow. It takes 450+ms to check a token.Generating tokens takes 1.6s and above. What could be the reason? How can I improve the performance of my microservice ?

Details:

  • Auth and Microservices are running on my laptop

  • The time I mentioned is for the auth server with requests from only one microservice

    Thanks in advance

Community
  • 1
  • 1
Sachin Titus
  • 1,960
  • 3
  • 23
  • 41

2 Answers2

1

Download a tool such as VisualVM to perform profiling of your application.

I would also record the elapsed time of individual methods to determine exactly which methods are taking the longest amounts of time.

Once you can verify exactly what code is taking awhile, you can attempt JVM optimizations, or review the code (if you're using an external library) and verify the implementation.

StevenPG
  • 311
  • 4
  • 16
  • how can I monitor time elapsed for a function in spring? – Sachin Titus Apr 12 '20 at 18:28
  • 1
    long start = System.currentTimeMillis(); // some time passes long end = System.currentTimeMillis(); long elapsedTime = end - start; Places the currentTimeMillis calls at the start and end of methods, print elapsed time at the end. It's not a Spring library function. – StevenPG Apr 12 '20 at 18:32
  • Thank you . I suspect Bcrypt which im using. Any way to improve it's performance? Is there some other function which is fast and secure? – Sachin Titus Apr 12 '20 at 18:34
  • 1
    I would see what other libraries are out there. Also look online for bcrypt specific optimizations. I'm sure if it's bcrypt, it's a common problem that others have solved! – StevenPG Apr 12 '20 at 18:37
  • I'll try ur solution and update comments – Sachin Titus Apr 12 '20 at 18:39
  • Do u suggest reducing number of rounds with BCrypt? – Sachin Titus Apr 12 '20 at 18:45
  • I would remove bcrypt and use noop first, see how long it takes. Then perform a very basic run-through, time it. Then time your current implementation. This should tell you how much additional rounds are affecting the runtime. Is your laptop slow or old? That may affect the runtime as well. – StevenPG Apr 12 '20 at 18:47
  • mine is a ROG gaming laptop. I'll test that thanks – Sachin Titus Apr 12 '20 at 18:53
0

There might be three reasons,

  • Your services might be in different regions and OAuth2 server might be central one and in different region. If this is the case create instance of OAuth servers in all regions which you use so that your latency can be improved.
  • Check the Encryption techniques you used. always it's preferred to use SHA-256 Hashing but this might not be complete reason in some cases this could help.
  • Check your OAuth server Capacity, i.e. it's RAM processor and Storage volume. It might also be reason that multiple services makes same /generatetoken call to server and Tomcat makes it as One Thread per request and if this the case configuring your connection pool will also help.