Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
jefer94 committed Jul 4, 2024
1 parent bcd8a15 commit 75d9d38
Show file tree
Hide file tree
Showing 1,668 changed files with 135,920 additions and 117,095 deletions.
12 changes: 7 additions & 5 deletions benchmarks/django-workers/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError("Couldn't import Django. Are you sure it's installed and "
'available on your PYTHONPATH environment variable? Did you '
'forget to activate a virtual environment?') from exc
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions benchmarks/django-workers/myapp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class MyappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myapp'
default_auto_field = "django.db.models.BigAutoField"
name = "myapp"
8 changes: 4 additions & 4 deletions benchmarks/django-workers/myapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name='MyModel',
name="MyModel",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('value', models.IntegerField()),
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("name", models.CharField(max_length=100)),
("value", models.IntegerField()),
],
),
]
70 changes: 35 additions & 35 deletions benchmarks/django-workers/myapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

aserialize = sync_to_async(serialize)

res = requests.get('https://jsonplaceholder.typicode.com/posts')
res = requests.get("https://jsonplaceholder.typicode.com/posts")
stored = res.content


Expand All @@ -26,137 +26,137 @@ async def async_range(count):

async def async_seed(request: HttpRequest, id: Optional[int] = None):
async for i in async_range(30):
await MyModel.objects.aget_or_create(name=f'name{i}', value=i)
await MyModel.objects.aget_or_create(name=f"name{i}", value=i)

return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


def json_view(request: HttpRequest, id: Optional[int] = None):
if id is not None:
return JsonResponse({'name': 'name', 'value': 1})
return JsonResponse({"name": "name", "value": 1})

return JsonResponse([{'name': 'name', 'value': 1}], safe=False)
return JsonResponse([{"name": "name", "value": 1}], safe=False)


async def async_json_view(request: HttpRequest, id: Optional[int] = None):
if id is not None:
return JsonResponse({'name': 'name', 'value': 1})
return JsonResponse({"name": "name", "value": 1})

return JsonResponse([{'name': 'name', 'value': 1}], safe=False)
return JsonResponse([{"name": "name", "value": 1}], safe=False)


def json_query_view(request: HttpRequest, id: Optional[int] = None):
if id is not None:
res = MyModel.objects.aget(id=id)
if res is None:
raise HttpResponseNotFound('not found')
raise HttpResponseNotFound("not found")

return JsonResponse({'name': res.name, 'value': res.value})
return JsonResponse({"name": res.name, "value": res.value})

keys = request.GET.keys()
params = {k: request.GET[k] for k in keys}
l = MyModel.objects.filter(**params)
return JsonResponse([{'name': x.name, 'value': x.value} for x in l], safe=False)
return JsonResponse([{"name": x.name, "value": x.value} for x in l], safe=False)


async def async_json_query_view(request: HttpRequest, id: Optional[int] = None):
if id is not None:
res = await MyModel.objects.aget(id=id)
if res is None:
raise HttpResponseNotFound('not found')
raise HttpResponseNotFound("not found")

return JsonResponse({'name': res.name, 'value': res.value})
return JsonResponse({"name": res.name, "value": res.value})

keys = request.GET.keys()
params = {k: request.GET[k] for k in keys}
l = MyModel.objects.filter(**params)
return JsonResponse([{'name': x.name, 'value': x.value} async for x in l], safe=False)
return JsonResponse([{"name": x.name, "value": x.value} async for x in l], safe=False)


def template_view(request: HttpRequest):
l = MyModel.objects.filter()
return render(request, 'my_template.html', {'my_objects': l})
return render(request, "my_template.html", {"my_objects": l})


async def async_template_view(request: HttpRequest):
l = MyModel.objects.filter()
return render(request, 'my_template.html', {'my_objects': [x async for x in l]})
return render(request, "my_template.html", {"my_objects": [x async for x in l]})


def gateway_1s_view(request: HttpRequest):
# eventbrite bug
time.sleep(1)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


async def async_gateway_1s_view(request: HttpRequest):
# eventbrite bug
await asyncio.sleep(1)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


def gateway_3s_view(request: HttpRequest):
# eventbrite bug
time.sleep(3)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


async def async_gateway_3s_view(request: HttpRequest):
# eventbrite bug
await asyncio.sleep(3)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


def gateway_10s_view(request: HttpRequest):
# eventbrite bug
time.sleep(10)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


async def async_gateway_10s_view(request: HttpRequest):
# eventbrite bug
await asyncio.sleep(10)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


def requests_view(request: HttpRequest):
# eventbrite bug
try:
response = requests.get('https://jsonplaceholder.typicode.com/posts', timeout=60)
response = requests.get("https://jsonplaceholder.typicode.com/posts", timeout=60)
json = response.json()
except Exception:
return HttpResponse('timeout', status=408)
return HttpResponse("timeout", status=408)
return JsonResponse(json, safe=False)


async def async_requests_view(request: HttpRequest):
# eventbrite bug
try:
response = requests.get('https://jsonplaceholder.typicode.com/posts', timeout=60)
response = requests.get("https://jsonplaceholder.typicode.com/posts", timeout=60)
json = response.json()
except Exception:
return HttpResponse('timeout', status=408)
return HttpResponse("timeout", status=408)
return JsonResponse(json, safe=False)


def httpx_view(request: HttpRequest):
# eventbrite bug
try:
response = httpx.get('https://jsonplaceholder.typicode.com/posts', timeout=60)
response = httpx.get("https://jsonplaceholder.typicode.com/posts", timeout=60)
json = response.json()
except Exception:
return HttpResponse('timeout', status=408)
return HttpResponse("timeout", status=408)
return JsonResponse(json, safe=False)


async def async_httpx_view(request: HttpRequest):
# eventbrite bug
async with httpx.AsyncClient(http2=True) as client:
try:
response = await client.get('https://jsonplaceholder.typicode.com/posts', timeout=60)
response = await client.get("https://jsonplaceholder.typicode.com/posts", timeout=60)
json = response.json()
except Exception:
return HttpResponse('timeout', status=408)
return HttpResponse("timeout", status=408)

return JsonResponse(json, safe=False)

Expand All @@ -165,11 +165,11 @@ async def async_aiohttp_view(request: HttpRequest):
# eventbrite bug
async with aiohttp.ClientSession() as session:
try:
async with session.get('https://jsonplaceholder.typicode.com/posts', timeout=60) as response:
async with session.get("https://jsonplaceholder.typicode.com/posts", timeout=60) as response:
json = await response.json()
return JsonResponse(json, safe=False)
except Exception:
return HttpResponse('timeout', status=408)
return HttpResponse("timeout", status=408)


def brotli_view(request: HttpRequest):
Expand All @@ -185,22 +185,22 @@ async def async_brotli_view(request: HttpRequest):
def fake_cache_hit_view(request: HttpRequest):
# latency issue
time.sleep(0.02)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


async def async_fake_cache_hit_view(request: HttpRequest):
# latency issue
await asyncio.sleep(0.02)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


def fake_cache_set_view(request: HttpRequest):
# with brotli
time.sleep(0.2)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})


async def async_fake_cache_set_view(request: HttpRequest):
# with brotli
await asyncio.sleep(0.2)
return JsonResponse({'status': 'ok'})
return JsonResponse({"status": "ok"})
2 changes: 1 addition & 1 deletion benchmarks/django-workers/mysite/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

application = get_asgi_application()
app = application
Loading

0 comments on commit 75d9d38

Please sign in to comment.