Browse Source

[Python] Django: update to v3.2.18 (#8174)

Oleg S 2 years ago
parent
commit
c4405139cc

+ 13 - 13
frameworks/Python/django/benchmark_config.json

@@ -16,14 +16,14 @@
       "language": "Python",
       "language": "Python",
       "flavor": "Python3",
       "flavor": "Python3",
       "orm": "Full",
       "orm": "Full",
-      "platform": "None",
+      "platform": "WSGI",
       "webserver": "Meinheld",
       "webserver": "Meinheld",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
       "display_name": "Django",
       "display_name": "Django",
-      "notes": "CPython 3.6",
+      "notes": "",
       "versus": "wsgi",
       "versus": "wsgi",
-      "tags": ["broken"]
+      "tags": [ ]
     },
     },
     "socketify-wsgi": {
     "socketify-wsgi": {
       "plaintext_url" : "/plaintext",
       "plaintext_url" : "/plaintext",
@@ -31,17 +31,17 @@
       "port": 8080,
       "port": 8080,
       "approach": "Realistic",
       "approach": "Realistic",
       "classification": "Fullstack",
       "classification": "Fullstack",
-      "database": "MySQL",
+      "database": "None",
       "framework": "django",
       "framework": "django",
       "language": "Python",
       "language": "Python",
       "flavor": "Python3",
       "flavor": "Python3",
-      "orm": "Full",
-      "platform": "None",
+      "orm": "Raw",
+      "platform": "WSGI",
       "webserver": "Socketify.py",
       "webserver": "Socketify.py",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
       "display_name": "Django [Socketify.py WSGI]",
       "display_name": "Django [Socketify.py WSGI]",
-      "notes": "CPython 3.6",
+      "notes": "",
       "versus": "wsgi"
       "versus": "wsgi"
     },
     },
     "socketify-wsgi-pypy": {
     "socketify-wsgi-pypy": {
@@ -50,12 +50,12 @@
       "port": 8080,
       "port": 8080,
       "approach": "Realistic",
       "approach": "Realistic",
       "classification": "Fullstack",
       "classification": "Fullstack",
-      "database": "MySQL",
+      "database": "None",
       "framework": "django",
       "framework": "django",
       "language": "Python",
       "language": "Python",
       "flavor": "PyPy3",
       "flavor": "PyPy3",
-      "orm": "Full",
-      "platform": "None",
+      "orm": "Raw",
+      "platform": "WSGI",
       "webserver": "Socketify.py",
       "webserver": "Socketify.py",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
@@ -76,14 +76,14 @@
       "language": "Python",
       "language": "Python",
       "flavor": "Python3",
       "flavor": "Python3",
       "orm": "Full",
       "orm": "Full",
-      "platform": "None",
+      "platform": "WSGI",
       "webserver": "Meinheld",
       "webserver": "Meinheld",
       "os": "Linux",
       "os": "Linux",
       "database_os": "Linux",
       "database_os": "Linux",
       "display_name": "Django",
       "display_name": "Django",
-      "notes": "CPython 3.6",
+      "notes": "",
       "versus": "wsgi",
       "versus": "wsgi",
-      "tags": ["broken"]
+      "tags": [ ]
     }
     }
   }]
   }]
 }
 }

+ 6 - 6
frameworks/Python/django/config.toml

@@ -14,7 +14,7 @@ database = "MySQL"
 database_os = "Linux"
 database_os = "Linux"
 os = "Linux"
 os = "Linux"
 orm = "Full"
 orm = "Full"
-platform = "None"
+platform = "WSGI"
 webserver = "Meinheld"
 webserver = "Meinheld"
 versus = "wsgi"
 versus = "wsgi"
 
 
@@ -26,8 +26,8 @@ classification = "Fullstack"
 database = "MySQL"
 database = "MySQL"
 database_os = "Linux"
 database_os = "Linux"
 os = "Linux"
 os = "Linux"
-orm = "Full"
-platform = "None"
+orm = "Raw"
+platform = "WSGI"
 webserver = "Socketify.py"
 webserver = "Socketify.py"
 versus = "wsgi"
 versus = "wsgi"
 
 
@@ -39,8 +39,8 @@ classification = "Fullstack"
 database = "MySQL"
 database = "MySQL"
 database_os = "Linux"
 database_os = "Linux"
 os = "Linux"
 os = "Linux"
-orm = "Full"
-platform = "None"
+orm = "Raw"
+platform = "WSGI"
 webserver = "Socketify.py"
 webserver = "Socketify.py"
 versus = "wsgi"
 versus = "wsgi"
 
 
@@ -55,6 +55,6 @@ database = "Postgres"
 database_os = "Linux"
 database_os = "Linux"
 os = "Linux"
 os = "Linux"
 orm = "Full"
 orm = "Full"
-platform = "None"
+platform = "WSGI"
 webserver = "Meinheld"
 webserver = "Meinheld"
 versus = "wsgi"
 versus = "wsgi"

+ 2 - 2
frameworks/Python/django/django-postgresql.dockerfile

@@ -1,10 +1,10 @@
-FROM python:3.9.1-buster
+FROM python:3.9-bullseye
 
 
 ADD ./ /django
 ADD ./ /django
 
 
 WORKDIR /django
 WORKDIR /django
 
 
-RUN pip install -r /django/requirements.txt
+RUN pip install -r /django/requirements-gunicorn.txt
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 

+ 1 - 1
frameworks/Python/django/django-socketify-wsgi-pypy.dockerfile

@@ -8,4 +8,4 @@ RUN pip install -r /django/requirements-socketify.txt
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
-CMD python ./django-socketify-wsgi.py
+CMD python ./django-socketify-wsgi.py

+ 1 - 1
frameworks/Python/django/django-socketify-wsgi.dockerfile

@@ -8,4 +8,4 @@ RUN pip install -r /django/requirements-socketify.txt
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
-CMD python ./django-socketify-wsgi.py
+CMD python ./django-socketify-wsgi.py

+ 8 - 3
frameworks/Python/django/django-socketify-wsgi.py

@@ -1,9 +1,13 @@
-from socketify import WSGI
 import os
 import os
+import sys
 import multiprocessing
 import multiprocessing
 import logging
 import logging
+import socketify
 
 
-from hello_socketify.hello.wsgi import application
+app_dir = os.path.dirname(os.path.abspath(__file__)) + '/hello'
+sys.path.append(app_dir)
+
+from hello.wsgi import application as app
 
 
 
 
 _is_travis = os.environ.get('TRAVIS') == 'true'
 _is_travis = os.environ.get('TRAVIS') == 'true'
@@ -14,7 +18,8 @@ if _is_travis:
 
 
 
 
 def run_app():
 def run_app():
-    WSGI(application).listen(8080, lambda config: logging.info(f"Listening on port http://localhost:{config.port} now\n")).run()
+    msg = f"Listening on port 8080 now\n"
+    socketify.WSGI(app).listen(8080, lambda config: logging.info(msg)).run()
 
 
 
 
 def create_fork():
 def create_fork():

+ 2 - 2
frameworks/Python/django/django.dockerfile

@@ -1,10 +1,10 @@
-FROM python:3.9.1-buster
+FROM python:3.9-bullseye
 
 
 ADD ./ /django
 ADD ./ /django
 
 
 WORKDIR /django
 WORKDIR /django
 
 
-RUN pip install -r /django/requirements.txt
+RUN pip install -r /django/requirements-gunicorn.txt
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 

+ 6 - 3
frameworks/Python/django/gunicorn_conf.py

@@ -5,7 +5,7 @@ import sys
 _is_pypy = hasattr(sys, 'pypy_version_info')
 _is_pypy = hasattr(sys, 'pypy_version_info')
 _is_travis = os.environ.get('TRAVIS') == 'true'
 _is_travis = os.environ.get('TRAVIS') == 'true'
 
 
-workers = multiprocessing.cpu_count() * 3
+workers = int(multiprocessing.cpu_count() * 2.5)
 if _is_travis:
 if _is_travis:
     workers = 2
     workers = 2
 
 
@@ -16,11 +16,14 @@ pidfile = 'gunicorn.pid'
 pythonpath = 'hello'
 pythonpath = 'hello'
 
 
 if _is_pypy:
 if _is_pypy:
-    worker_class = "tornado"
+    worker_class = "sync"
 else:
 else:
     worker_class = "meinheld.gmeinheld.MeinheldWorker"
     worker_class = "meinheld.gmeinheld.MeinheldWorker"
 
 
     def post_fork(server, worker):
     def post_fork(server, worker):
-        # Disalbe access log
+        import meinheld
         import meinheld.server
         import meinheld.server
+        import meinheld.patch
         meinheld.server.set_access_logger(None)
         meinheld.server.set_access_logger(None)
+        meinheld.set_keepalive(keepalive)
+        meinheld.patch.patch_all()

+ 7 - 2
frameworks/Python/django/hello/hello/settings.py

@@ -7,18 +7,23 @@ ADMINS = ()
 
 
 MANAGERS = ADMINS
 MANAGERS = ADMINS
 
 
+_django_db = os.getenv('DJANGO_DB', "")
+
 DATABASES = {
 DATABASES = {
     'default': {
     'default': {
-        'ENGINE': 'django.db.backends.' + os.environ['DJANGO_DB'], # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+        'ENGINE': 'django.db.backends.' + _django_db, # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
         'NAME': 'hello_world',           # Or path to database file if using sqlite3.
         'NAME': 'hello_world',           # Or path to database file if using sqlite3.
         'USER': 'benchmarkdbuser',       # Not used with sqlite3.
         'USER': 'benchmarkdbuser',       # Not used with sqlite3.
         'PASSWORD': 'benchmarkdbpass',   # Not used with sqlite3.
         'PASSWORD': 'benchmarkdbpass',   # Not used with sqlite3.
-        'HOST': 'tfb-database',  # Set to empty string for localhost. Not used with sqlite3.
+        'HOST': 'tfb-database',          # Set to empty string for localhost. Not used with sqlite3.
         'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
         'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
         'CONN_MAX_AGE': 30,
         'CONN_MAX_AGE': 30,
     }
     }
 }
 }
 
 
+if not _django_db:
+    DATABASES = { }
+
 TIME_ZONE = 'America/Chicago'
 TIME_ZONE = 'America/Chicago'
 LANGUAGE_CODE = 'en-us'
 LANGUAGE_CODE = 'en-us'
 USE_I18N = False
 USE_I18N = False

+ 0 - 0
frameworks/Python/django/hello_socketify/hello/__init__.py


+ 0 - 52
frameworks/Python/django/hello_socketify/hello/settings.py

@@ -1,52 +0,0 @@
-import os
-
-DEBUG = False
-
-SECRET_KEY = '_7mb6#v4yf@qhc(r(zbyh&z_iby-na*7wz&-v6pohsul-d#y5f'
-ADMINS = ()
-
-MANAGERS = ADMINS
-
-DATABASES = {}
-
-TIME_ZONE = 'America/Chicago'
-LANGUAGE_CODE = 'en-us'
-USE_I18N = False
-USE_L10N = False
-USE_TZ = False
-
-MEDIA_ROOT = ''
-MEDIA_URL = ''
-STATIC_ROOT = ''
-STATIC_URL = '/static/'
-STATICFILES_DIRS = ()
-STATICFILES_FINDERS = ()
-MIDDLEWARE = ()
-
-ROOT_URLCONF = 'hello_socketify.hello.urls'
-WSGI_APPLICATION = 'hello_socketify.hello.wsgi.application'
-
-TEMPLATES = [
-    {
-        'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': [],
-        'APP_DIRS': True,
-        'OPTIONS': {},
-    },
-]
-
-INSTALLED_APPS = (
-    'django.contrib.contenttypes',
-    'django.contrib.sessions',
-    'hello_socketify.world',
-)
-
-LOGGING = {
-    'version': 1,
-    'disable_existing_loggers': True,
-    'handlers': {},
-    'loggers': {},
-
-}
-
-ALLOWED_HOSTS = ['*']

+ 0 - 7
frameworks/Python/django/hello_socketify/hello/urls.py

@@ -1,7 +0,0 @@
-from django.urls import re_path
-from ..world.views import plaintext, json
-
-urlpatterns = [
-    re_path(r'^plaintext$', plaintext),
-    re_path(r'^json$', json)
-]

+ 0 - 21
frameworks/Python/django/hello_socketify/hello/wsgi.py

@@ -1,21 +0,0 @@
-"""
-WSGI config for hello project.
-
-This module contains the WSGI application used by Django's development server
-and any production WSGI deployments. It should expose a module-level variable
-named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
-this application via the ``WSGI_APPLICATION`` setting.
-
-Usually you will have the standard Django WSGI application here, but it also
-might make sense to replace the whole Django WSGI application with a custom one
-that later delegates to the Django one. For example, you could introduce WSGI
-middleware here, or combine a Django application with an application of another
-framework.
-
-"""
-import os
-
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello_socketify.hello.settings")
-
-from django.core.wsgi import get_wsgi_application
-application = get_wsgi_application()

+ 0 - 0
frameworks/Python/django/hello_socketify/world/__init__.py


+ 0 - 14
frameworks/Python/django/hello_socketify/world/views.py

@@ -1,14 +0,0 @@
-from json import dumps
-
-from django.http import HttpResponse
-
-
-def plaintext(request):
-    return HttpResponse("Hello, World!", content_type="text/plain")
-
-
-def json(request):
-    return HttpResponse(
-            dumps({"message": "Hello, World!"}),
-            content_type="application/json"
-        )

+ 4 - 0
frameworks/Python/django/requirements-gunicorn.txt

@@ -0,0 +1,4 @@
+-r requirements.txt
+greenlet==0.4.17
+gunicorn==20.1.0
+meinheld==1.0.2

+ 1 - 1
frameworks/Python/django/requirements-socketify.txt

@@ -1,2 +1,2 @@
-Django==4.1.7
+-r requirements.txt
 git+https://github.com/cirospaciari/socketify.py.git@main#socketify
 git+https://github.com/cirospaciari/socketify.py.git@main#socketify

+ 4 - 6
frameworks/Python/django/requirements.txt

@@ -1,8 +1,6 @@
-Django==4.1.7
-greenlet==0.4.17
-gunicorn==20.0.4
-meinheld==1.0.2
+Django==3.2.18
 mysqlclient==1.4.6
 mysqlclient==1.4.6
-psycopg2==2.8.6
+psycopg2==2.9.6; implementation_name=='cpython'
+psycopg2cffi==2.9.0; implementation_name=='pypy'
 pytz==2020.4
 pytz==2020.4
-ujson==5.4.0
+ujson==5.4.0