Caching issue with Flask + Python SDK

Comments

5 comments

  • Bilal Al-Shahwany

    Hi Namrata, When using uwsgi, usually it does not support multi-threading, only process based architecture, that is why we cannot use the SDK with memory cache, since it usually use multi-threading to sync the cache.

    That is why we suggest to use external cache for uWsgi and configure triggering these SDK threads that will sync to the cache. 

    Have you followed the steps to configure the SDK cache in uWsgi?

    Thanks

    Bilal

    0
    Comment actions Permalink
  • Namrata Patel

    Yes. Kind of :-) 

    I was able to follow the steps and get the caching working. Just curious though if there is any documentation on best practices around how to keep the Prod and Dev connection separate. We have flask application that on Dev we run without uwsgi directly using flask server. But on Prod we use uwsgi. Is there a nice way of keeping these configs only when the env is Prod because you need to set these when the connection is created and not after. I am refering to this section https://help.split.io/hc/en-us/articles/360020359652-Python-SDK#2-create-a-spooler-and-set-up-the-tasks

    0
    Comment actions Permalink
  • Bilal Al-Shahwany

    Hi Namrata, Based on the SDK instructions, to enable the uWSGI cache you need to set SDK config parameter "'uwsgiClient' to "True", so you can set it to "False" for Dev environment.

    Thanks

    Bilal

    0
    Comment actions Permalink
  • John Penner

    Bilal Al-Shahwany

    A little surprised the SDK with memory caching doesn't work as our uwsgi server running flask is configured to only use a single process with multiple threads. Or does the library have trouble with the fact the uwsgi server has a master process managing the child flask process?

    See below for our uwsgi config params:

    UWSGI_NUM_PROCESSES='1'
    UWSGI_NUM_THREADS='15'
    UWSGI_UID='uwsgi'
    UWSGI_GID='uwsgi'
    UWSGI_BUFFER_SIZE='12288'
    UWSGI_TIMEOUT='90'
    UWSGI_HEADERS='Connection:Keep-Alive'

    cd /var/app

    # Flask support
    UWSGI_MODULE='--module application:app'

    # defaulting to application.py if not explicitly set
    [ -z "${WSGI_PATH}" ] && WSGI_PATH=application.py

    uwsgi --http :8080 --chdir /var/app --wsgi-file ${WSGI_PATH} ${UWSGI_MODULE} --master --processes ${UWSGI_NUM_PROCESSES} --threads ${UWSGI_NUM_THREADS} --uid ${UWSGI_UID} --gid ${UWSGI_GID} -t ${UWSGI_TIMEOUT} --http-keepalive --add-header ${UWSGI_HEADERS} --buffer-size ${UWSGI_BUFFER_SIZE}

    0
    Comment actions Permalink
  • Bilal Al-Shahwany

    Hi John, it depends if the SDK code is loaded into a flask child process that support multi-threading, then in theory, it will download the cache and use it to calculate treatment, I am wondering if the process is killed too soon, or the flask child process is not multi-threaded.

    I can test the same configuration on my end and let you know.

    Thanks

    Bilal

    0
    Comment actions Permalink

Please sign in to leave a comment.