-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade from 1.x to 2.x has broken code with models magic getters/setters #11995
Comments
Maybe we should create an optimizer called is_private in Zephir, so the ORM does not have to use Reflection |
Wait, 8 total calls and 21 seconds spend on this ? What a hell. how this is possible ? Can someone post code for reproduce for this ? Im not sure if this is an issue, beacause one call for ReflectionClass:getProperty in php user land is like 5E-5 Or you mean is it done on this 400 resultset like 20 seconds ? Can you post this table and code to reproduce problem ? I just checked it on some 400 random results, selected them using |
@Jurigag , Simple test: install Phalcon 1.3.6, send request to api – get response in <1s, upgrade Phalcon to 2.x, send same request – get response in >20s. No other changes, 100% repeatable (on multiple versions in my subject post). Request will look like (in my concrete project) I can trim my project (and make it as small as possible to reproduce issue) to post it in public for debugging and testing that later patch really solves issue. But remember – i use Phalcon with ps: xDebug was disabled in all tests (and don't even installed). XhProf doesn't make any overhead by-design. |
But as i wrote you. I checked it on 400 records setting:
I don't have slow execeution. Just that's why we need some script te reproduce, beacause i can't maybe andres can't. |
@Jurigag , it's not enough to just "get some models from repository". You need to:
As i said, i don't know right now how exactly it works inside, especially with combination of magic setters (and don't have enough time and computer near me until 2-7 august). But simple test with upgrading Phalcon to version with mentioned PR – breaks this code. Workaround in my post – solves issue. I think that Example part from $models = \Acme\Models\Driver::find(['limit' => 100]);
$transformer = new \Acme\Transformers\Driver();
$collection = new \League\Fractal\Resource\Collection($models, $transformer->setPartials([]), 'Driver');
$transformerManager->parseIncludes(['cars', 'docs', 'passengers']);
return $transformerManager->createData($collection); Example part of public function includeCars(\Acme\Model\Driver $driver) { return $this->collection($driver->getCars() , new \Acme\Transformers\Driver , 'Driver' ); }
public function includeDocs(\Acme\Model\Driver $driver) { return $this->collection($driver->getDocs() , new \Acme\Transformers\Doc , 'Doc' ); }
public function includePassengers(\Acme\Model\Driver $driver) { return $this->collection($driver->getPassengers(), new \Acme\Transformers\Passenger, 'Passenger'); } |
Relations doesn't have anything here beacause you don't join them. They will be there if you will access them(additional queries) As I wrote I already checked _isVisible it doesn't bottleneck for me, we just need whole script to reproduce it. Well i was writeng this on mobile, i see you probably access them ? Some code example is really needed right now. I don't have It's no point for andres for adding something to zephir if we are not sure for 100% use case. As you see above i have super small times of executing just on setting some random property which is executing all those phalcon internal method you have and don't have ANY bottlenecks. Those transformers don't havy anything to do here. As you see it's internally ReflectionClass::getProperty in _isVisible which is really simple method. Whatever you do there shouldn't do anything fancy. You could just try do: $models = \Acme\Models\Driver::find(['limit' => 100]);
$models->someProperty = "someValue" And according to your enviroment you should have some slowliness too. |
@trogwarz Could you please check the |
@trogwarz Waiting for you |
As ReflectionClass was removed I think this is fixed, also declare properties on every model must speed up any application. |
Results of testing (ubuntu 12.04, 14.04) with different versions of php-fpm and phalcon: [
{
"v-php-fpm" : "5.6.23-1+deprecated+dontuse+deb.sury.org~precise+1",
"v-phalcon" : "1.3.6",
"time-php" : 0.0746169090271,
"time-db" : 0.026349306106567
},
{
"v-php-fpm" : "5.6.23-1+deprecated+dontuse+deb.sury.org~precise+1",
"v-phalcon" : "2.0.13",
"time-php" : 26.32877898216248,
"time-db" : 0.079745054244995
},
{
"v-php-fpm" : "5.6.23-1+deprecated+dontuse+deb.sury.org~precise+1",
"v-phalcon" : "2.1.0 RC 1",
"time-php" : 28.077505111694336,
"time-db" : 0.02750825881958
},
{
"v-php-fpm" : "5.6.23-1+deprecated+dontuse+deb.sury.org~precise+1",
"v-phalcon" : "3.0.0",
"time-php" : 26.12922596931458,
"time-db" : 0.032534837722778
},
{
"v-php-fpm" : "5.6.24-1+deb.sury.org~precise+1",
"v-phalcon" : "1.3.6",
"time-php" : 0.36090803146362,
"time-db" : 0.30925035476685
},
{
"v-php-fpm" : "5.6.24-1+deb.sury.org~precise+1",
"v-phalcon" : "2.0.13",
"time-php" : 26.84207701683,
"time-db" : 0.1939103603363
},
{
"v-php-fpm" : "5.6.24-1+deb.sury.org~precise+1",
"v-phalcon" : "2.1.0 RC 1",
"time-php" : 27.166598796844,
"time-db" : 0.10126161575317
},
{
"v-php-fpm" : "5.6.24-1+deb.sury.org~precise+1",
"v-phalcon" : "3.0.0",
"time-php" : 26.581640958786,
"time-db" : 0.023773193359375
}
]
Preparing XhProf dumps, right now, and trimming my app to give you example of code. Just wait for a bit – i'm after fulltime work now. |
@trogwarz Can you please compile using 3.0.x branch, fix hasn't landed into master yet |
@andresgutierrez, am i doing it right? git clone git://github.com/phalcon/cphalcon.git /tmp/cphalcon
cd /tmp/cphalcon/build
git checkout 3.0.x
./install
service php5.6-fpm restart
php -r "echo Phalcon\Version::get();" |
@trogwarz For dev branches use this aproach: ...
git checkout 3.0.x
zephir fullclean && zephir build # use latest zephir here
... |
@sergeyklay , oops, didn't know. Tested with build like you said on ubuntu 12.04/14.04 and php5.6/php7.0 – cool! Now works fast, yay! Thank you! |
Prerequisites
ppa:ondrej/php
and from deprecatedppa:ondrej/php5-5.6
too)Phalcon 1.3.x (tested mostly on 1.3.6)
API response less than 1 second, about 5-7 megabytes RAM. XhProf shows that slowest point is
\file_exists
in composer autoload. Cool, fast.Phalcon 2.x (tested mostly on 2.0.10)
Strange happens. API response 40-60 seconds, very huge RAM eating (1 gigabyte and more plus swap), 100% eats one CPU core.
XhProf shows that bottleneck is
\ReflectionClass::getProperty
and traces leading to\Phalcon\Mvc\Model\Resultset\Simple::current
. After some digging into, i found that PR #11417 made my code totally broken. Callgraph attached at the end of this post.Workaround
As a workaround i can extend magic setter of model in my base model and copy-paste some code from sources like this:
But, i think, this is a crooked nail. In my company and projects, we use only setters/getters for models and repos and don't care about setting like
$model->someprop = 'foobar'
(thus, it's not affectstoArray
call behaviour).Questions
getModelsMetadata
(that can be cached!)?Thanks for any suggestions.
Callgraph
The text was updated successfully, but these errors were encountered: