How to suspend appstats for one request on App Engine / Java?

I usually run appstats fulltime in my sandbox app. However, I have one complicated operation (basically restoring the stock database) that causes appstats to explode my instance by throwing OutOfMemoryErrors. Even with large instance sizes, it still fails. Appstats just wants too much RAM.

I do not need appstats for this request. Ideally, I will call the method any ThreadLocal object responsible for building the appstats and tell him to trick his thumbs in a few minutes.

I considered expanding AppstatsFilter to ignore specific URLs, but a violation request executes as a deferred task and identifies it along the way a little more complicated.

How can I tell appstats to pause?

Just in case, this is unclear: downloading the version of my application with disabling appstats, launching my task, and then downloading the version with the applications turned on is what I'm doing now. I do not want to do this.

+7
source share
3 answers

What I did was write my own CustomAppstatsFilter and exclude specific URLs.

public class CustomAppstatsFilter extends AppstatsFilter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { String url = ((HttpServletRequest) request).getRequestURL().toString(); // We do not want these to show up in appstats if ((url.contains("appstats")) || url.contains("_ah/") || url.contains("cron/") || url.contains("batch/")) { chain.doFilter(request, response); return; } else { super.doFilter(request, response, chain); } } } } 

EDIT - this can be combined with ZiglioNZ's excellent answer.

 <!-- Appstats filter for profiling application --> <filter> <filter-name>appstats</filter-name> <filter-class>my.company.filter.CustomAppstatsFilter</filter-class> <init-param> <param-name>maxLinesOfStackTrace</param-name> <param-value>5</param-value> </init-param> </filter> <filter-mapping> <!-- excludes are in CustomAppstatsFilter --> <filter-name>appstats</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 
+2
source
Good question. For Python, the answer is simple:
 from google.appengine.ext.appstats import recording class ...(webapp.RequestHandler): def get(self): recording.dont_record() ... 

Maybe there is a similar API in Java?

Alternatively, again, the Python version has a flexible way to filter write requests; I think in the Java version you can accomplish a similar thing using the entries and entries in your web.xml. (See Java application documents appstats.)

+1
source

Jeff, I wonder if this will help you reduce the appearance of OutOfMemoryErrors: How to reduce Appstats memory usage in Google App Engine Java

 <filter> <filter-name>appstats</filter-name> <filter-class>com.google.appengine.tools.appstats.AppstatsFilter</filter-class> <init-param> <param-name>maxLinesOfStackTrace</param-name> <param-value>16</param-value> </init-param> </filter> 
+1
source

All Articles