Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodelay #680

Merged
merged 11 commits into from
Dec 15, 2015
Merged

Nodelay #680

merged 11 commits into from
Dec 15, 2015

Conversation

asvetlov
Copy link
Member

Second approach to solve nodelay issue

def tcp_nodelay(self):
return self._tcp_nodelay

def set_tcp_nodelay(self, value):
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, why not setter fortcp_nodelay property?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about property's setter but found that syscall worth explicit function call.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

if value not in (1,0):
    raise ValueError('.....')

@asvetlov
Copy link
Member Author

I'm finished.
Regular response and file uploading uses TCP_CORK to push all data in a single packet.
Streaming response and websocket use TCP_NODELAY to minimize latency.

Flow can be controlled by set_tcp_nodelay() and set_tcp_cork() calls. tcp_nodelay and tcp_cork states are mutually exclusive, case with neither nodelay nor cork is possible also (current aiohttp works exactly under this case).

I'll merge PR tomorrow. The only thing left is documentation.

@socketpair
Copy link
Contributor

Is stream uncorked after writing last byte of response while in keep-alive mode ?

@socketpair
Copy link
Contributor

Also, same technique should be applied to http client when it writes http request.

@socketpair
Copy link
Contributor

I remember interesting technique in streaming over http and using chunked data. This cover not only EvenrSource http://www.w3schools.com/html/html5_serversentevents.asp but also videostreaming.

I mean that in these cases each chunk of chunked response contains complete data that should be delivered to browserwith minimal delay. Even when delay between chunks are long. So, in current implemntation, user should uncork manually after sending chunk and cork again before sending chunk. Does not it ? If yes, please document that example.

Also for websockets. Library should cork before sending frame and uncork afer sending. Is it so ?

Sorry, but code slightly complicated for me.

asvetlov added a commit that referenced this pull request Dec 15, 2015
@asvetlov asvetlov merged commit cf3c7a4 into master Dec 15, 2015
@asvetlov asvetlov added this to the 0.20 milestone Dec 15, 2015
@asvetlov asvetlov deleted the nodelay branch December 17, 2015 10:06
@asvetlov asvetlov mentioned this pull request Dec 18, 2015
@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants