oTree Forum >

Deploying on Heroku with gunicorn

#1 by David

Dear Chris,

Would it be possible to deploy an oTree app on Heroku using gunicorn (https://devcenter.heroku.com/articles/python-gunicorn)? I am hoping to enable usage of multiple dynos and thus allow for concurrent processing of requests.

My motivating problem is, that my oTree app runs nowhere close to smoothly even when using the most powerful performance dyno L. My app is a market simulation based on the double auction market at https://www.otreehub.com/projects/?featured=1. However due to some modifications I have a lot of data getting live send frequently, which leads to at least 1 server request per participant per second. I aim to handle 300-500 market participants at the same time.


#2 by Chris_oTree

oTree doesn't work with gunicorn and is designed to run single threaded.

Can you describe why you are making 1 request per participant per second? That will lead to a huge load on the server. Even if you can run multiple server processes, you would probably run into a bottleneck with access to the postgres DB.

#3 by David

My participants receive information (their evaluation of the good and data series to draw a chart of their evaluations of the good), which depends on the time since their last trade happened and updates every second. 

As this information is also quite payoff-relevant I am reluctant to move the processing to javascript where tech savvy participants could potentially manipulate the data to their own advantage.

#4 by Chris_oTree

I would look into offloading more of this calculation into client-side javascript code. If someone made a trade, then you can update everyone who is affected by it. But if nobody made a trade in the last second, then there shouldn't be a need to keep querying the server.

#5 by David

Would it be possible to trigger the live_method from the python side? I am thinking of triggering it e.g. every second based on a timer or similar.

This could be an alternative that at least gets rid of all the clients' update queries to server, as the server would simply send an update each and every second without the need to receive some update triggering message from the client side upfront.

#6 by Chris_oTree

That is not supported, sorry.

#7 by ccrabbe

Hi David -

One workaround for this might be that you could set things up to have one extra player in the group, and connect to that client yourself (using a known participant.label or just with id_in_subsession=1 and make sure you connect your client first).  

Then have that client load a special "Monitor" Page instead of the regular market Page, and use javascript on that Monitor page to send a live_message every second (which triggers an update to the rest of the group).

That, at least, would cut down on the flurry of incoming "please update" messages from the whole group.

You could also do this without the extra client - and just have id_in_group=0 be the one who sends the single javascript message every second triggering the group update. But then if that one subject disconnects nobody else would get updates.  Safer, I think, to have an extra client under your control.


#8 by Chris_oTree

Yes that is a good solution.

#9 by David

Hi --Chris,

Thanks for your proposal. We indeed also thought of this solution. It is easy to implement as we already have an "admin player" who is played by us anyways (to change market parameters like taxes on the go).

However, I am wondering whether this might lead to problems if the client of the "admin player" is idle for too long (say over night)? I believe the Websocket connection might be interrupted after a certain timeout and this would stop updates for all other participants.


Write a reply

Set forum username