0
b2plane
1y

Just cut down registration from 5s api response (because its sending email confirmation) into 70ms using rabbitmq (emails are now delegated in rabbit queue and sent whenever the queue takes place)

But still around 70ms to register which is great and fast (because it also generates jwt token and returns the whole user object + jwt) so its difficult to keep this at 7-9ms response time

Is this normal and is it fine to leave it at 70 or can this be optimized (or should it be)?

Comments
  • 3
    Are you getting more than 1 request every 70ms?
  • 1
    why was your controller/response waiting for the confirmation email to be sent to begin with?
    wrap the email-logic in a new thread and start it, so the response is sent and the only overhead is the thread-creation-time

    the code inside the thread can update the DB whether it was successfully sent/delivered/error

    why use a queue unless you're expecting thousands of users where ur worried that ur SMTP/email-handler will start hitting the rate limit?
  • 0
    @spongessuck i dont know im still in development phase its not yet in production
  • 0
    @azuredivay nothing happened when i annotated the method with @Async in java but i googled and read around that people recommend using rabbitmq or kafka for sending mails which makes a lot of sense and solves this problem. Rabbitmq queues emails in a topic and sends them whenever the mail method processes in the background thread, leaving the user not having to wait until the email gets sent
  • 0
    @b2plane ah, even in an async method, the next instruction (ie ur response return) will still wait for its completion if you 'await' it
    https://javatpoint.com/thread-conce... use threads, but make sure the state changes are thread-safe
  • 0
    @azuredivay i got rid of the async annotation and replaced the entire thing with rabbitmq listener
  • 4
    70ms is fine.
    Hell, 2000ms on signup submission would be fine.

    Your signup isn’t a bottleneck — and if it is, you’re going to have serious load problems once those new users start using.
Add Comment