-
Notifications
You must be signed in to change notification settings - Fork 414
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
Global state on redis not shared between processes #307
Comments
Here's a quick script (redis_test.py) I wrote to be used by gunicorn/redis:
I invoked this with the following command So now if you want to use WSGI I think you can simply create a
and then invoke Seems to be working correctly for me. What exception or behavior are you seeing that is looking wrong? BTW, thanks for your submission 🙏 |
Hi Andrew, Thanks for your answer. Here are more information about what I'm trying to accomplish :
@api_view(['POST'])
def create_dtale_server(request, name):
df = some_function()
dtale.show(df, host=ACTIVE_HOST, ignore_duplicate=True, name=name)
@api_view(['GET'])
def get_all_dtale_servers(request):
curr_data = global_state.get_data()
instances = []
for data_id in curr_data.keys():
data_obj = DtaleData(data_id, build_url(str(ACTIVE_PORT), ACTIVE_HOST))
metadata = global_state.get_metadata(data_id)
name = metadata.get("name")
# convert pandas timestamp to python dateTime
time = pd.Timestamp(metadata.get("start"), tz=None).to_pydatetime()
datetime = time.strftime("%Y-%m-%d %H:%M:%S")
instances.append(
{
'id': data_id,
'name': name,
'url': data_obj.build_main_url(data_id=data_id),
'datetime': datetime
}
)
return Response(instances) Now, the behaviour that looks wrong to me is:
It is worth noting that when I launch my django app without gunicorn, there is only one worker so everything works perfectly. I can try to write a minimalist Django app to show you, if you want, but it will take some time. Please tell me if it is needed. Thanks for your help ! :) |
So I'm not using django, but I was able to get mine working using Flask and the following:
The only problem that I have to look into is that when running with gunicorn if I try to specify a route for Now if you're sticking with Django I did build out a sample app which allows you to still incorporate D-Tale into your app. Here is the source Let me know if you have any questions. Good luck 🙏 |
Ughh, nevermind. I completely forgot to set the workers to a value greater than 1. You're right this seems to be a problem with using redis with gunicorn. Let me see if I can find another solution. |
@sunderww so this was stupid on my part. Looks like redis will re-create the DB as each process connects to it. I was able to prove this out by simply running following:
So from there I wondered "well what if I was able to start up all my flask workers at once then everything should be fine". So I ran the following command: And from there everything seemed to work as expected. So the key is Let me know if it works for you and I'll work on drafting some documentation |
Thanks soooo much for your help, and sorry for the late reply, I didn't have time to explore your solution before today. I used preload when starting gunicorn and it worked perfectly ! Now everything is working like I wanted and I can use the awesome features of D-Tale :D
Can you elaborate on that ? As I understand it, I could just write a few lines where I call
Can I offer some help on that ? |
Oh that's awesome! Glad to hear it. Here's my documentation so far: https://github.com/man-group/dtale/blob/bugfixes_20201102/docs/GUNICORN_REDIS.md So feel free to just upload any updates to that file here or just wait until I try releasing this stuff this weekend and you can create a PR to the repo for any changes you want to make. I might also try adding an example of what you're asking about for pre-loading a dataframe up front to be shared. |
@sunderww just wanted to give you a heads up that I merged that documentation into master and I fixed that issue with overriding routes on gunicorn in the release I just put out v1.21.0. Feel free to close this issue if you think it's complete, thanks |
@aschonfeld The documentation on D-Tale with flask and D-Tale with Django is very clear, nice work !
I actually don't need to do that. I just wanted to understand more clearly, so don't trouble yourself with this if that wasn't on your priorities 😃
Yes everything works perfectly now, so I'll close the issue. Thanks again for your help :) |
So here's an example of some code that does some preloading of data on startup (bear in mind this won't work with the current version because I found a bug):
Make a note of these lines:
Now if you start that up using gunicorn when you bring it up in a browser you should see an instance already available: And then you can see the data by jumping directly to Now this is using meaningless data, but if you wanted some sort of reference data available when the application starts this is how you'd do it. The good thing is that it apparently works 😄 (well of course after I release that bugfix) |
Hi,
I'm trying to serve D-Tale servers from a Django API. The API is responsible for retrieving the correct data, and then calls
dtale.show(df)
.As stated in the documentation, D-Tale does use a different set of globals in each gunicorn process, so I used
dtale.global_state.use_redis_store('/home/jdoe/dtale_data')
.I wrote this line in my Django project's
wsgi.py
file, where I provide the application variable for gunicorn.The code is correctly called (I can see the redis databases in the provided path), but the global_state is still not shared between the python processes.
I can't figure out why it is not working as intended. Did I call use_redis_store in the wrong place ? Did I need to do something else ? Or is use_redis_store not working properly ?
The documentation is quite light on this subject and I have no idea where else to look.
Thanks in advance.
The text was updated successfully, but these errors were encountered: