Summary of key knowledge of network programming + concurrent programming

One: network programming

  Goal: Write a software based on network communication with C/S or B/S architecture

  1, C / S, B / S (priority)

  C/S: The client is also the client, which is used by the user and communicates with the server (server) through the network;

  Advantages: The software used by the company is relatively stable;

  Disadvantages: It needs to be downloaded and installed independently, which is troublesome;

 

  B/S: browser is also a browser, which can be used as a client and communicate with the server through the network;

  Advantages: no need to install the client independently, convenient and fast;

 

  server <==================>client

  Server Features:

    1. Uninterrupted service until the end of the world;

    2. The server must support concurrency + high performance

    2. Internet 
Internet = physical connection medium + Internet protocol (OSI seven layers***)

tcp handshake three times, wave four times (*****)
tcp is reliable, but not as efficient as udp (*****)
udp is not Reliable, but efficient (*****)

3. socket (*****) The
socket abstraction layer is located between the transport layer and the application layer

4. Socket communication based on the tcp protocol (*****)
Plus the connection loop
plus the communication loop

5. The sticky packet problem: (*****)
The unique sticky packet problem of the tcp streaming protocol
Solution: the custom header

udp datagram protocol has no sticky packet problem

6. Remote command execution

7. Socket communication based on udp protocol (***)


2. Concurrent programming Objective
: To enable the server to support high concurrency + high performance

1. Operating system History of development
Multi-channel technology (*****)
generation background
Core of multi-channel technology:
1. Multiplexing in space
2. Multiplexing in time

*****
Concurrency: It seems to run at the same time
并行:真正意义上的同时运行,一个cpu同一时刻只能做一件事
只有多核才能同时做多件事,即并行的效果


2、进程
1、进程理论(*****)
2、开启进程的两种方式(*****)
3、守护进程(**)
4、互斥锁与信号量(**)
5、IPC机制:队列,管道(*)
6、进程queue=管道+锁 (***)
7、生产者消费者模型(*****)

3、线程
1、线程理论(*****)
2、开启线程的两种方式(*****)
3、守护线程(**)
4、互斥锁与信号量(**)
5、GIL vs 互斥锁(*****)
6、Cpython的解释器下(*****)
多个任务是IO密集型:多线程
多个任务是计算密集型:多进程
7、死锁现象与递归锁(**)
8、线程queue(***)
9、Event事件(**)

4、池(*****)
为何要用池:
操作系统无法无限开启进程或线程
池作用是将进程或线程控制操作系统可承受的范围内
什么时候用池:
当并发的任务数要远超过操作系统所能承受的进程数或
线程数的情况应该使用池对进程数或线程数加以限制

如何用池?
池内装的东西有两种:
装进程:进程池
装线程:线程池

进程线程池的使用


提交的两种方式:
同步调用
异步调用+回调机制

任务执行的三种状态:
阻塞
阻塞
非阻塞:
就绪
运行



5、单线程下实现并发(****)
协程:在应用程序级别实现多个任务之间切换+保存状态

高性能:
单纯地切换,或者说么有遇到io操作也切换,反而会降低效率
检测单线程下的IO行为,实现遇到IO立即切换到其他任务执行

gevent

6、IO模型(主要掌握理论****)
阻塞IO
非阻塞IO
IO多路复用
异步IO

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325268046&siteId=291194637