Skip to content

Use persistent HTTP requests by default.#109

Closed
yoeo wants to merge 3 commits into
sendgrid:masterfrom
yoeo:master
Closed

Use persistent HTTP requests by default.#109
yoeo wants to merge 3 commits into
sendgrid:masterfrom
yoeo:master

Conversation

@yoeo

@yoeo yoeo commented Jul 15, 2015

Copy link
Copy Markdown

Using persistent HTTP requests (Connection: Keep-Alive) allows to send messages four to five times faster.

Benchmark result with 10 000 mails sent with a persistent connections (Connection: Keep-Alive), and 10 000 other mails sent with "normal" connections:

$ python test_benchmark_10k_mails.py
persistent . . . . . . . . . .
nonpersistent . . . . . . . . . .
duration_persistent = 242.951007 sec
duration_nonpersistent = 1227.724485 sec
messages sent 5.053383 times faster with persistence

Benchmark code here: http://pastebin.com/5mSu452V

yoeo added 2 commits July 15, 2015 15:45
Using persistent HTTP requests (Connection: Keep-Alive) allows to send messages four to five times faster.
Comment thread sendgrid/sendgrid.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to ignore timeout for persistent requests?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm launching a non-persistent call as a fall-back when the persistent call fails (timeout).
That's why I'm ignoring the error.

But I agree that it looks a bit odd...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the comment could be Timeout on persistent request, falling back to non-persistent request.

Btw, will falling back to non-persistent requests going to help?

@yoeo

yoeo commented Jul 16, 2015

Copy link
Copy Markdown
Author

I updated the comment.

About the fall-back, I don't really know how Sendgrid servers react when there are too much hanging (persistent) requests at the same time. The servers could refuse new persistent requests and still accept the non-persistent ones, knowing that non-persistent requests usually release server resources faster.

@thinkingserious

Copy link
Copy Markdown
Contributor

Hello @yoeo!

Thank you very much for this update!

We will not be adding this to the core library; however, we suggest you create a helper once we get that feature up, you can track progress here: #169

That said, we love the fact you took the time to create this and we want to swag you out. Please shoot us an email at [email protected] :)

For now, I'd suggest creating a sub-class and perhaps writing up your implementation. I'd be happy to support that blog post with some Twitter love.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants