Very slow response from the server when signup/login #5230
-
I'm using django-allauth to handle user signup/login. The current setup works, but the response from the server is incredibly slow (>15s, other types of responses are usually <500ms). In base.py (I used cookiecutter-django to setup everything), the relevant settings are LOGIN_REDIRECT_URL = "myapp:home"
LOGIN_URL = "account_login"
ACCOUNT_SIGNUP_REDIRECT_URL = reverse_lazy("myapp:accept-terms-of-service")
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_ADAPTER = "project.users.adapters.AccountAdapter" In adapters.py, class AccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request: HttpRequest) -> bool:
return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)
def send_mail(self, template_prefix, email, context):
mailing_thread = threading.Thread(
target=super().send_mail,
args=(template_prefix, email, context),
)
mailing_thread.start() In views.py class CustomLoginView(LoginView):
def form_valid(self, form):
response = super().form_valid(form)
user_id = self.request.user.id
if not UserProfile.objects.filter(user_id=user_id).exists():
return redirect("myapp:accept-terms-of-service")
return response
def home(request):
return render(request, "myapp/home.html") The idea is to send a verification email to the user when he signs up. And when he first signs in, he will need to go to the process of accepting the legal documents. The responses of two requests are very slow: 1. When the user is signing up, there is a significant delay before the server makes a response, though ultimately the user receives the correct email. 2. When the user first logs in, there is a significant delay before showing the accept terms page. I have tried to use both django celery and threads to send the email, but the delay doesn't change at all (BTW all of them works, just very slow). So it's probably not a blocking problem. I am not sure if this is related to how boto3 is configured because it seems that AWS SES is ultimately sending the right email. But the following appears in the terminal each time when a user signs up:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
[Note: cross-posted to pennersr/django-allauth#3978 and anymail/django-anymail#386.] |
Beta Was this translation helpful? Give feedback.
-
Are you using the debug toolbar? It can be slow with many queries. Attach a profiler and you will find the slowiness. |
Beta Was this translation helpful? Give feedback.
-
@medmunds @foarsitter The problem is due to RedisCache. I used ssh tunnels to test the local dev version of the same project on the server, and the slow page response issues never came up. After that, in my CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": env("REDIS_URL"),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
# Mimicing memcache behavior.
# https://github.com/jazzband/django-redis#memcached-exceptions-behavior
"IGNORE_EXCEPTIONS": True,
},
},
} with the following CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "",
},
} and using the production setting, the problems went away. My understanding is that in production, it is preferable to use RedisCache rather than MemCache, but I still haven't figured out why in this case Redis is causing trouble. |
Beta Was this translation helpful? Give feedback.
I dont know how IGNORE_EXCEPTIONS exactly behaves but I think it hides the exception behind all this.
Probably your redis url is invalid.