Slow performance, what could be my bottleneck?

Hey guys, so I have a controller that seems to be giving my app a little bit of a bottleneck. The page loads in about 4 seconds, which seems PAINFULLY slow. I’m working on my local development environment.

Basically the controller gets post data, then accesses 3 different models, has 3 different uses of findOne, and also sends an email using the mandrill extension.

Any idea on how I can speed this up or test to see where my bottleneck is? I’m relatively new to Yii2 development.

Also I do have indexes on the appropriate columns.

EDIT:

I found out it was one block of code that was causing the slowdown. This block integrates into my mailing list provider. Is there anyway to get the page to load first and THEN perform this function? Thanks in advance.

Yep. Could be done via JavaScript AJAX request.

Deferred for the win - jQuery :)

You say you are using Mandrill for your e-mail…

How are you connecting to them?

If you are using the Swiftmailer module, the you are connecting via SMTP. The problem with this is that SMTP is a ‘chatty protocol’. There are several network transaction that go back and forth between your app and the Mandrill server. Each one has to be acknowledged before the next one starts. Each one of these may take up to .25 seconds or so.

If you are using the Mandrill API interface, then the whole e-mail process is take care of in a single quick JSON transaction. If this is the case you will need to look somewhere else to find the bottleneck.

How many e-mail do you send a month? You might want to look at Mailgun. Same issues, but they have a nice free tier for fairly small mail volume. Mandrill got rid of their free tier a while back and went with $10 for the first 25,000 messages.

-John

Like this answer to. Send and forget without the wait.

I wasn’t sure about the AJAX approach but I ended up loading that block in an iframe and that worked pretty well for loading purposes. Any thoughts about this?