Performance issue in REST Api

Hello all,

We’ve developed an Yii2 application and a RESTFul Api for the same. The issue is, the response time taken for returning the results is significantly higher in Api than in the front-end, though we are using the same query in both applications.

Are there any general steps to follow for reducing the response time of api?

We’re using active query. Both applications are hosted under the same server.

PHP Version: 5.6

See attachments.

Also see the SO post

No. I’d take a profiler such as blackfire or xhprof and check what’s actually slow. Then deal with it if it’s part of the app or deal with it and submit a pull request if it’s part of the framework.

Alright, we’ll try that. Thank you for your reply.

Please add sample query

After recently deploying a Yii2 REST app, we’ve also noticed that it is slower than the Yii v1 it was refactored from. The data models are pretty much the same, the database is exactly the same. The difference we are seeing is a lot less than OP (and I realize he was comparing Yii2 REST to non-REST, but I assume there are some similar issues), but still would like to see if we can speed it up a bit - it takes something in the order of 150-300ms more for the Yii2 REST app (450-650ms total) where the original Yii app, which on average takes about 300-400ms. The original app uses mostly non-AR select queries and the Yii2 one does use ActiveQuery/AR etc. – it’s pretty much an out-of-the-box Yii2 REST implementation.

The Yii2 app is on PHP 7 and the original app is 5.6, so it’s not a 1-1 comparison, however I had hoped PHP 7 would make up for the Yii2 REST framework overhead. I can try porting over some of the non-AR endpoints from the original app and get some timings on those to have a closer comparison.

I realize this is not enough to yield specific "fix" advice, but I do wonder if anyone else has had similar experience and could offer general advice about optimizing Yii2 REST apps? Thanks.

I think AR may make a difference. Direct queries via builder are always faster. But re-writing everything using query builder looks like a bad move to me so I’d start with profiling the API and getting exact reason of why it’s not fast enough.

@IDG did you figure out what was causing your delay? I’m having similar performance issues with the rest service with the out of box setup.

I’ve created a project based of REST API and my response is within 100ms if the query is not so complex.

I think you should do some profiling may be there is some issue in your code or may be your mysql queries are slow. To find out mysql queries you should turn your mysql slow query low on and trace down the issues. Thanks :)