Reputation: 184
I'm developing/serving currently locally.
I'm using django-admin for internal users to add items.
I add in my signal code. My signal is post_save and it's purpose is to send an email to a user for approval. I test my signal using console.EmailBackend
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
I add a new item, there is no performance impact to the web browser. My models item page reloads quickly.
I update my EMAIL_BACKEND too use smpt details
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
I add a new item, the performance impact is massive, my web browser now takes 15-30 seconds to to reload the items page after adding.
Any thoughts around why the performance is so terrible?
Upvotes: 0
Views: 319
Reputation: 857
If you plan on running your application on AWS or similar, consider using an email sending service (such as AWS's SES). It will let you set up sender verification (DKIM/SPF) and it'll be a low-latency API call rather than the slow SMTP interaction. If you're planning on using AWS, there is already a lib, django-ses, which you can configure and begin using immediately.
If you want to continue sending the emails yourself, set up an asynchronous task queue and worker, using celery or channels. This deferral will let your web worker continue serving requests, while the worker finishes the slow process of sending.
If you want a really speedy setup, you could combine the two above approaches, deferring email sending to an asynchronous worker which then hits an email-as-a-service API. Your web worker will be snappy, and your async worker won't be blocked talking to an SMTP server for 10-15 seconds!
Upvotes: 1
Reputation: 1527
Real e-mail send is slow in nature.
I recommend recommend sending an email using asynchronous Queue task. For example Celery is good library for asynchronous Queue task.
Upvotes: 2