Uploaded image for project: 'DataStax Python Driver for Apache Cassandra'
  1. PYTHON-237

Can't detect gevent monkey patch when using with uwsgi --gevent-monkey-patch option

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.1.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Environment:

      uwsgi 1.9.17
      flask 0.9
      cassandra 1.2.6
      cassandra driver 2.1.2

    • Sprint:
      Py P-DEF

      Description

      I'm using the driver in a uwsgi+flask+cassandra app. uwsgi runs with the option '--gevent-monkey-patch', which will
      1. initialize the wsgi app
      2. start event loop
      3. apply gevent monkey patch

      This means the driver is imported before gevent monkey patch. So the following code in cluster.py won't choose GeventConnection as default connection class(instead it defaults to AsyncoreConnection on my environment.)

      if 'gevent.monkey' in sys.modules:
          from cassandra.io.geventreactor import GeventConnection as DefaultConnection
      elif _is_eventlet_monkey_patched():
          from cassandra.io.eventletreactor import EventletConnection as DefaultConnection
      else:
          try:
              from cassandra.io.libevreactor import LibevConnection as DefaultConnection  # NOQA
          except ImportError:
              from cassandra.io.asyncorereactor import AsyncoreConnection as DefaultConnection  # NOQA
      

      It causes a very high cpu load in my uwsgi process, seems gevent and AsyncoreConnection doesn't work for each other.
      Someone has submitted a similar issue to uwsgi https://github.com/unbit/uwsgi/issues/701. In uwsgi 2.1, --gevent-early-monkey-patch option is added to solve the issue.

      However I'm thinking about the above code. If we can decide which connection class to use in a later time instead of when imported, the problem would be solved. I'm not sure if it's feasible to make the change. Any thoughts?

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              thoslin thoslin
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

                Estimated:
                Original Estimate - 2 days
                2d
                Remaining:
                Remaining Estimate - 2 days
                2d
                Logged:
                Time Spent - Not Specified
                Not Specified