Why does Symfony2 profiler throw 404s when using MemcachedProfilerStorage?
I am trying to determine the reason for a 404 while using the Symfony2 profiler. I am using Symfony 2.3 LTS.
I have a profiler included in our development environments and the problem is reproducible on multiple development machines. Our configuration for the profiler:
framework:
profiler:
dsn: "memcached://localhost:11211"
enabled: true
lifetime: 86400 # Keep profiles for a day at most
On some, but not all pages, we see an error like this:
**The page at https://local.dev says:**
An error occurred while loading the web debug toolbar (404: Not Found).
Do you want to open the profiler?
OK / Cancel
There are 5,404 requests for https://local.dev/_wdt/<token>
, and clicking Cancel takes us to the "Token Not Found" page inhttps://local.dev/_profiler/<token>
I've tried going through the code and so far I've defined:
- If I put a breakpoint at in , I can define a unique parent token.
ProfilerListener
onKernelResponse
- Then
$this->saveProfiles($profile);
I can manually telnet the memcached for the token and get the expected serialized array. - If I go through the code, I end up in a
TraceableEventDispatcher
. TheresaveInfoInProfile
is a loop above the children of the profile that calls$this->saveInfoInProfile($child, true);
. In my case, there are 6 baby items and the first 5 are saved as expected. - After 5 iterations, the
saveInfoInProfile
original token can be retrieved via telnet and still appears. - In the sixth (last) iteration, the call is made at before .
MemcachedProfilerStorage
$this->getMemcached()->set($key, $value, time() + $expiration);
- Before this call is made, I can still get the original token via telnet.
However, after this call is made, the telnet request for the original token is returned empty. The key for this call is different from the original token, so it is not overwritten.
This in turn causes the 404 error that I see on the client side.
Additional potentially useful information:
- The toolbar works on some pages. It contains 404 toolbar errors in our admin interface.
- We are using ESI and using Twig.
- We call on
{% render(controller("ABundle:AController:anAction", {some:params})) %}
- Eliminating the issue of one render method from one of our Twig templates fixes the issue.
- Reusing this render method and annotating a different one will fix the problem as well. Assuming there are too many children or too much data (or something similar).
What could be causing this problem? How can I identify a fix?
As an aside, using FileProfiler works correctly.
Thanks for the help!
source to share
I discovered the solution after a big headbutt.
It seems that due to the fact that we use a lot of visualizations in our templates, a lot of profiler data is being collected.
The profiler data is inserted into memcached. And since there are many of them, other data is evicted. I discovered this by running:
echo stats | nc 127.0.0.1 11211 | grep evic
And every time I load a page, I saw the rose evicted_unfected
and evictions
.
The solution was to increase the size of the memcached memory pool from the standard 64 MB to 256 MB (or any other size).
This is done by passing a parameter -m
at runtime.
source to share