PYTHON__ System: Socket_tcp Supplement, co-process

Source: Internet
Author: User
Tags ack epoll

TCP three-time handshake: SYN------Syn+ack and ACK

Four waves: fin-to-ack (FIN)--and ACK

TCP 10 states: LISTEN syn_sent Syn_recv established fin_wait1 fin_wait2 close_wait last_ack time_wait CLOSED

MSL: Maximum message survival time

4 times the handshake completes the connection close, the active close the connection one party after the 3rd time handshake completes sends the fourth time handshake the ACK packet to enter the TIME_WAIT state, must stay in this state twice the MSL time, waits for 2MSL time the main purpose is afraid the last ACK packet the other party seizes, Then the other side after the timeout will be re-send the third handshake fin bag, active close to the re-issued Fin packet can be sent again an ACK reply packet.

The TCP server model is implemented in several ways: single-process non-clogging: Use Select.setblocking () to turn sockets into non-clogging types.

Using Select to implement Select.select () can be polled to ask which sockets have tasks. (Send and receive data, exception)

Epoll:select.epoll () time notification mechanism, greatly improved efficiency

coprocessor : The Greenlet module in Python is similar to a thread but not equal to a thread, and requires Greenlet.switch () to switch the calling process manually.

If you want to switch automatically, use gevent:gevent to rewrite the time-consuming stuff (functions, classes). So you can only use it inside to achieve the time-consuming operation, such as Gevent.socket (), Gevent.sleep (), to create a co-process With Gevent.spawn (), you need to add a sentence before executing the code gevent.monkey.patch_all () it will modify the code, recompile, so that the process can be manipulated like a thread. It's just a time-consuming operation to switch back and forth.

PYTHON__ System: Socket_tcp Supplement, co-process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.