diff --git a/bench/asgi_wsgi/flask-wsgi.py b/bench/asgi_wsgi/flask-wsgi.py index 84cb118..c9f0e8c 100644 --- a/bench/asgi_wsgi/flask-wsgi.py +++ b/bench/asgi_wsgi/flask-wsgi.py @@ -10,6 +10,6 @@ def index(): response.content_type = "text/plain" return response - -WSGI(app).listen(8000, lambda config: print(f"Listening on port http://localhost:{config.port} now\n")).run() +if __name__ == "__main__": + WSGI(app).listen(8000, lambda config: print(f"Listening on port http://localhost:{config.port} now\n")).run() diff --git a/bench/django-asgi/hello/__init__.py b/bench/django-asgi/hello/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bench/django-asgi/hello/asgi.py b/bench/django-asgi/hello/asgi.py new file mode 100644 index 0000000..aa968ab --- /dev/null +++ b/bench/django-asgi/hello/asgi.py @@ -0,0 +1,21 @@ +""" +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.settings") + +from django.core.asgi import get_asgi_application +application = get_asgi_application() diff --git a/bench/django-asgi/hello/settings.py b/bench/django-asgi/hello/settings.py new file mode 100644 index 0000000..d73a219 --- /dev/null +++ b/bench/django-asgi/hello/settings.py @@ -0,0 +1,52 @@ +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.urls' +WSGI_APPLICATION = 'hello.wsgi.application' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': {}, + }, +] + +INSTALLED_APPS = ( + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'world', +) + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'handlers': {}, + 'loggers': {}, + +} + +ALLOWED_HOSTS = ['*'] diff --git a/bench/django-asgi/hello/urls.py b/bench/django-asgi/hello/urls.py new file mode 100644 index 0000000..a0b7f07 --- /dev/null +++ b/bench/django-asgi/hello/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from world.views import plaintext, json + +urlpatterns = [ + path('plaintext', plaintext, name='plaintext'), + path('json', json, name='json'), +] diff --git a/bench/django-asgi/requirements.txt b/bench/django-asgi/requirements.txt new file mode 100644 index 0000000..2368091 --- /dev/null +++ b/bench/django-asgi/requirements.txt @@ -0,0 +1,2 @@ +django==4.1.4 +git+https://github.com/cirospaciari/socketify.py.git@main#socketify diff --git a/bench/django-asgi/world/__init__.py b/bench/django-asgi/world/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bench/django-asgi/world/views.py b/bench/django-asgi/world/views.py new file mode 100644 index 0000000..992df35 --- /dev/null +++ b/bench/django-asgi/world/views.py @@ -0,0 +1,13 @@ +from json import dumps +from django.http import HttpResponse + + +async def plaintext(request): + return HttpResponse("Hello, World!", content_type="text/plain") + + +async def json(request): + return HttpResponse( + dumps({"message": "Hello, World!"}), + content_type="application/json" + ) \ No newline at end of file diff --git a/bench/django-wsgi/hello/__init__.py b/bench/django-wsgi/hello/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bench/django-wsgi/hello/settings.py b/bench/django-wsgi/hello/settings.py new file mode 100644 index 0000000..d73a219 --- /dev/null +++ b/bench/django-wsgi/hello/settings.py @@ -0,0 +1,52 @@ +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.urls' +WSGI_APPLICATION = 'hello.wsgi.application' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': {}, + }, +] + +INSTALLED_APPS = ( + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'world', +) + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'handlers': {}, + 'loggers': {}, + +} + +ALLOWED_HOSTS = ['*'] diff --git a/bench/django-wsgi/hello/urls.py b/bench/django-wsgi/hello/urls.py new file mode 100644 index 0000000..a0b7f07 --- /dev/null +++ b/bench/django-wsgi/hello/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from world.views import plaintext, json + +urlpatterns = [ + path('plaintext', plaintext, name='plaintext'), + path('json', json, name='json'), +] diff --git a/bench/django-wsgi/hello/wsgi.py b/bench/django-wsgi/hello/wsgi.py new file mode 100644 index 0000000..717367e --- /dev/null +++ b/bench/django-wsgi/hello/wsgi.py @@ -0,0 +1,21 @@ +""" +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.settings") + +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() diff --git a/bench/django-wsgi/requirements.txt b/bench/django-wsgi/requirements.txt new file mode 100644 index 0000000..2368091 --- /dev/null +++ b/bench/django-wsgi/requirements.txt @@ -0,0 +1,2 @@ +django==4.1.4 +git+https://github.com/cirospaciari/socketify.py.git@main#socketify diff --git a/bench/django-wsgi/world/__init__.py b/bench/django-wsgi/world/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bench/django-wsgi/world/views.py b/bench/django-wsgi/world/views.py new file mode 100644 index 0000000..d7b7c43 --- /dev/null +++ b/bench/django-wsgi/world/views.py @@ -0,0 +1,13 @@ +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" + ) \ No newline at end of file diff --git a/misc/bench-bar-graph-asgi.png b/misc/bench-bar-graph-asgi.png new file mode 100644 index 0000000..82ff921 Binary files /dev/null and b/misc/bench-bar-graph-asgi.png differ diff --git a/misc/bench-bar-graph-general.png b/misc/bench-bar-graph-general.png new file mode 100644 index 0000000..796bb46 Binary files /dev/null and b/misc/bench-bar-graph-general.png differ diff --git a/misc/bench-bar-graph-wsgi.png b/misc/bench-bar-graph-wsgi.png new file mode 100644 index 0000000..4fbf56b Binary files /dev/null and b/misc/bench-bar-graph-wsgi.png differ diff --git a/misc/bench-bar-graph.png b/misc/bench-bar-graph.png index 5bf7351..796bb46 100644 Binary files a/misc/bench-bar-graph.png and b/misc/bench-bar-graph.png differ diff --git a/src/socketify/cli.py b/src/socketify/cli.py index 3558fe9..9846fad 100644 --- a/src/socketify/cli.py +++ b/src/socketify/cli.py @@ -1,5 +1,6 @@ import inspect import os +import logging from . import App, AppOptions, AppListenOptions help = """ Usage: python -m socketify APP [OPTIONS] @@ -81,7 +82,8 @@ def load_module(file, reload=False): if is_factory(module): app = app() return app - except: + except Exception as error: + logging.exception(error) return None def execute(args): arguments_length = len(args)