Yii Framework Forum: Performance issue in REST Api - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Performance issue in REST Api general practices to follow

#1 User is offline   Musafar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 07-December 13
  • Location:Kochi

Posted 29 July 2016 - 01:34 AM

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

Attached File(s)


0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,184
  • Joined: 17-January 09
  • Location:Russia

Posted 29 July 2016 - 06:41 AM

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.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#3 User is offline   Musafar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 07-December 13
  • Location:Kochi

Posted 03 August 2016 - 12:28 AM

View Postsamdark, on 29 July 2016 - 06:41 AM, said:

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.
0

#4 User is offline   Joji 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 04-June 12
  • Location:India

Posted 16 August 2016 - 05:21 AM

Please add sample query
0

#5 User is offline   ldg 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 13-October 09

Posted 05 June 2017 - 12:20 AM

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.
0

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,184
  • Joined: 17-January 09
  • Location:Russia

Posted 07 June 2017 - 07:54 AM

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.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#7 User is offline   skworden 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 516
  • Joined: 14-June 12
  • Location:Virginia, USA

Posted 30 June 2017 - 11:03 AM

@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.
0

#8 User is offline   chaudhary 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-May 12

Posted 11 July 2017 - 09:26 PM

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 :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users