Skip to content

Profiling might not work with CachePlugin #175

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

Merged
merged 6 commits into from
Jun 28, 2017
Merged

Profiling might not work with CachePlugin #175

merged 6 commits into from
Jun 28, 2017

Conversation

fbourigault
Copy link
Contributor

Q A
Bug fix? not yet
New feature? no
BC breaks? no
Deprecations? no
Related tickets N/A
Documentation N/A
License MIT

This a a failing functional test about profiling when the CachePlugin is involved.

When the cache is hit and the CachePlugin does not perform any cache validation, the ProfileClient is never reached. This cause the profiled stack about not being complete and will display empty boxes in the profiler panel.

@fbourigault
Copy link
Contributor Author

As a solution, we could move the ProfileClient code into the ProfilePlugin and let the ProfilePlugin fill all those data if not yet set. By doing so, the last executed plugin would fill the request data.

@fbourigault
Copy link
Contributor Author

I also added a failing test case when the plugin throw an Exception.

@fbourigault
Copy link
Contributor Author

I think the exception case can be handled with a try/catch block in the StackPlugin. The cache case could be handled by checking in every ProfilePlugin if ProfileClient job is done and do it if it's not the case. I will try those solutions as soon as possible.

@Nyholm
Copy link
Member

Nyholm commented Jun 25, 2017

👍

@fbourigault
Copy link
Contributor Author

Tests are now green 🎉.

I think I should work ProfilePlugin readability as it gets complicated with all those closures!

Also I'm open to any suggestion about not duplicating code between ProfileClient and ProfilePlugin (collectRequestInformation)

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im happy to merge. But I do not understand the changes in ProfilePlugin to 100%. But I do undertand the tests and they are all passing.

Fabien, If you want a third set of eyes on this then we should wait for David or Mark (or someone else?). If you are confident you can merge this.

(I really need to study Promises..)

"symfony/phpunit-bridge": "^3.2",
"symfony/twig-bundle": "^2.8 || ^3.0",
"symfony/twig-bridge": "^2.8 || ^3.0",
"symfony/web-profiler-bundle": "^2.8 || ^3.0",
"symfony/finder": "^2.7 || ^3.0",
"symfony/cache": "^3.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. php-cache is not good enough for you? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jokes aside, can you require this on sf2.8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if you use PHP 5.5.9+

@fbourigault
Copy link
Contributor Author

But I do not understand the changes in ProfilePlugin to 100%

Tell me I will try to explain :)

return $this->plugin->handleRequest($request, $wrappedNext, $wrappedFirst)->then(function (ResponseInterface $response) use ($profile) {
try {
$promise = $this->plugin->handleRequest($request, $wrappedNext, $wrappedFirst);
} catch (Exception $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From where is this exception thrown?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's thrown from any plugin or even the client.


/**
* Collect request information when not already done by the HTTP client. This happens when using the CachePlugin
* and the cache is hit without re-validation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean with "without re-validation"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean when the plugin does not add If-Modified-Since or If-None-Match header.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

* @param RequestInterface $request
* @param Stack|null $stack
*/
private function collectRequestInformation(RequestInterface $request, Stack $stack = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So running this does only have an impact when cache plugin and "without re-validation"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the request goes through the whole chain, request information will be already collected by the ProfileClient.


return $response;
}, function (Exception $exception) use ($profile) {
}, function (Exception $exception) use ($profile, $request, $stack) {
$profile->setFailed(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From where is this exception thrown?

How does it differ from https://github.com/php-http/HttplugBundle/pull/175/files#r124504876

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception can be thrown from anywhere too.

But, as some Http\Promise\Promise implementation does not catch all exceptions, we have to use both to catch exceptions in any case. See Http\Promise\FulfilledPromise and Http\Client\Promise\HttpfulfilledPromise for implementation differences.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey. I see. Thanks

@fbourigault fbourigault merged commit b893a16 into php-http:master Jun 28, 2017
@fbourigault fbourigault deleted the profiling-functional-tests branch June 28, 2017 15:12
@fbourigault
Copy link
Contributor Author

Thank you for reviewing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants