[2.1.4] Play mixing responses under high load

208 views
Skip to first unread message

František Hartman

unread,
Oct 1, 2013, 3:08:16 PM10/1/13
to play-fr...@googlegroups.com

I wrote some JMeter tests for my web app and found out that when cpu usage rises to 100 % and the response time rises to few seconds Play starts mixing the responses - for one request serves response of other request (but not the other way around). The mixed requests are always very close in time (few miliseconds apart). I am seeing this both on my local machine and staging environment.

I wrote very simple JMeter test case for a Play app that takes a variable in path and prints it in the page that reproduces this issue.

So for request like localhost:9000/123 displays page containing number 123, works for low load, with high load this will be mixed.


My environment:
Java 1.7
Play 2.1.4 (tried also 2.1.0)
Using simple authentication (see attached project)
for both play run and play stage

I couldn't reproduce this without the authentication.

Thanks for replies.

F.
play-high-cpu-load-test.zip

František Hartman

unread,
Oct 2, 2013, 7:25:44 AM10/2/13
to play-fr...@googlegroups.com

I have nailed the issue to my spring configuration.

Problem was that Play asked for instance of play.mvc.Security.AuthenticatedAction (calling the

public <A> A getControllerInstance(Class<A> clazz)

method. I delegate this to Spring bean lookup. So initially I added

<bean class="play.mvc.Security.AuthenticatedAction" />


which created only one instance. Following will create new instance each time it is requested

<bean class="play.mvc.Security.AuthenticatedAction" scope="prototype"/>

and the issue dissappears. The page http://www.playframework.com/documentation/2.1.1/JavaInjection should be updated with information which beans could be singletons and which not.

F.

Guillaume Bort

unread,
Oct 2, 2013, 10:42:13 AM10/2/13
to play-fr...@googlegroups.com
It shouldn't be a problem if you keep your controller instances totally stateless. If you keep a state related to a specific request (or set of requests) into the controller, then yes you need a new instance to serve each request.


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

Donovan Muller

unread,
Oct 3, 2013, 7:45:20 AM10/3/13
to play-fr...@googlegroups.com
I also stumbled into this the other day...

In my case, the symptom manifested itself when two requests (in this case a request to two different controllers for profile images) were fired off by .js on my page directly after each other.
The two requests would sometimes respond correctly (two distinct images returned) but if you refreshed a few times, you would start finding that one (i.e. the same) image would be returned for both requests.
After some digging, it looked like both requests would be routed to one controller when the same image was returned and not to two separate controllers as expected.
So refreshing would result in a lucky packet of which controllers got what requests. Either requests were routed as expected to both controllers or both requests to either one of the controllers...

I was using action composition to inject the authenticated user:

@Named
@Scope(SCOPE_PROTOTYPE)
public class InjectAuthenticatedUserAction extends Action<InjectAuthenticatedUser> {

    @Inject
    @Qualifier("DefaultCache")
    private Caching caching;

    @Inject
    private Context context;

    @Override
    public Result call(final Http.Context ctx) throws Throwable {
        ...
        return delegate.call(ctx);
    }
}

After I changed the bean scope to SCOPE_PROTOTYPE, all worked as expected...

Springs singleton scope also bit me with Websockets and how I injected things: http://stackoverflow.com/questions/17782901/websockets-with-multiple-tabs-windows
I have since fixed this as well by working around Spring's singleton scope (probably should answer my question :) )

Anton Ivinsky

unread,
May 4, 2015, 10:01:27 AM5/4/15
to play-fr...@googlegroups.com
Got same issue, responses are mixed in play 2.3.8 with securesocial authentication. How can it be solved? Any help?

Anton Ivinsky

unread,
May 4, 2015, 11:22:06 AM5/4/15
to play-fr...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages