Chapter XXVII: Concurrent Programming

UDP protocol 

User Datagram Protocol, is a protocol belonging to the transport layer in the OSI model of

Provided, unreliable, do not require sequential, small amount of data, fast transmission service

Unreliable:

Confirmation is not required after completion of transmission and delete data in the cache immediately

It does not require the order:

When the data is divided into a large number of data packets for transmission, the other party can not know the order of data, and are complete

A small amount of data:

The higher the greater the likelihood of data loss, it is recommended not to the amount of data over 1472

high speed:

TCP relative terms much faster do not need to confirm the information, nor the need to establish links

Communication Process

If TCP metaphor for the process of cell phone so UDP can be seen as walkie-talkie  

1. buy a machine to create a UDP socket

2. Fixed channel bind a ip and port

3. The transmitting and receiving data recvfrom sendto

 

receive

1. buy a machine to create a UDP socket

2. The transceive data recvfrom sendto

Be careful not to collect data must be received no clear port number port number is not possible to use network services

 

 

Other differences of TCP and UDP

1. There is no connection 

2. Each transmission is not a stick package independent packet   

 

TCP require a higher data integrity: online payment, text messages

UDP: data integrity is not required but faster: Video game voice 

DNS

Domain Name Server 

Domain name is a string of a regular string used to bind IP, the purpose is to facilitate memory

DNS server is to help you to convert the domain name to ip address 

Is essentially a database is kept inside the correspondence between domain names and ip  

A finite machine performance

Divided

Root name server only stores information defining domain name server 

Top-level domain servers store information only secondary domain name server 

Two memory three secondary domain name server

Three third-level domains can usually be stored directly saved four specific ip information 

.....................

DNS is used to resolve the local acceleration   

 

Build their own role in the DNS

1.CDN content delivery network services is to establish more mirrors around you   

2. Cluster  

operating system

Is a software,

Protected can not be arbitrarily modified 

A huge amount of code kernel 500 million or more

Longevity, once completed generally do not change

linux is the socks (shell Rights Reserved 2011!) grafted onto minux binding produced

The role of the operating system:

1. complex hardware details to hide the ugly, provides a simple call interface

2. The application for the hardware becomes orderly competition 

 

History of operating system development 

Computer punch cards and vacuum tubes 1. The first operating system with no process is not  

2. Second generation computer transistor 70941401 Batch System

Input and output devices can not be interconnected computing needs of people involved in the processing efficiency of the development group of a group of slow and serial execution

3. Third Generation Computer Technology integrated circuit and multi-channel

Multi-terminal line spooling   same machine both for scientific computing and general purpose computer do the character processing

Multi-channel technology to solve the inefficiencies caused by the serial

Multi-user terminal can simultaneously provide services to each user thought to yourself one computer for multiple users  

4. Fourth-generation PC

Large-scale use of integrated circuits, most of all provides a GUI interface 

Multi-channel technology  

Background, all programs leading to a waste of resources serial  

The purpose is to allow multiple programs can execute concurrently, handle multiple tasks simultaneously  

Key Technology

Spatial multiplexing

It refers to a plurality of different program data loaded in memory at the same time,

Each inter-process memory regions are isolated from each physical level 

Time-multiplexed  switch save +

Switching conditions:

1. The execution of a process encountered the IO operation to switch to other processes

2. The running time is too long, the operating system will be forcibly deprived of enforcement powers  

Simply switch is not enough, you must save the current state before switching, in order to resume execution 

 

process

A program being run on the process is called, is the program implementation process, an abstract concept

Process from the operating system 

 

 

multi-Progress

The difference between the process and procedures 

A computer program that can identify a bunch of files, the program is not running is lying on a pile of binary hard drive

When the program runs, to read data from the hard disk into memory, the CPU reads instructions from memory and execute,

Once the operation gave rise to the process   

A program can be executed multiple times to generate multiple processes, but are independent processes

When we run a right-py file, in fact, started a python interpreter, you actually py file as an argument to the interpreter  

 

Blocking non-blocking concurrent parallel (focus)

Obstruction: The program encountered io operation is entered the blocked state    

本地IO input      print     sleep    read  write      

Network IO recv send

Non-blocking: the program is not running on any IO operations unblocked 

He said blocking non-blocking state of the program is to run 

Concurrent: processing a plurality of tasks simultaneously appear, essentially performing very fast switching   

Parallel: multiple tasks simultaneously perform real must-have multi-core CPU only possible parallel 

He said concurrent parallel tasks are handled

Switching three states

 

Programmers eternal topic

Improve efficiency

The fundamental way is to let the program running as much as possible

Reduce IO multi-CPU time as possible    

Buffer is used to reduce IO operations 

 

 

Create a process of understanding and destruction

 

Recipe: is the program 

Cooking process: the process is

 

 

 

 

Two ways process (focus)

1. instantiated directly Process, tasks to be performed with incoming target

  

2. Process class inheritance, override the run method will be the task into the run method 

Import os 
from multiprocessing Import   Process
class MyProcess ( Process): DEF __init __ ( Self, name): . Super () __init __ () . Self name = name # inherited Procee override the run method will be executed tasks sent to run the DEF run ( Self) : Print ( . Self name) Print ( "! S running child processes%" % . os getpid ()) Print ( "! S over the child process%" % . os getpid ()) IF __name__ == '__main__': You do not have to specify the target parameter # created when p =
   
       
       
   
   
       
       
       


   
   MyProcess ( "Rose") the p-. Start () Print ( "parent over!")
   
   

 

join function (focus)

 

Process object includes a join function

Priority for improving child process, so that the parent process waits for the child process ends 

 

Zombies and orphaned understand

Orphaned

Means that the parent process to end, while the child is still running,

Orphaned harmless, there is need for its existence

For example: qq open the browser, qq first exit the browser should continue to run 

Orphaned operating system will be taken over   

 

Zombie process

Worth, the child process is over, but the operating system will keep some information process, such as PID, running time, this time on this process is called a zombie process

If too many zombie process will take up a lot of resources, resulting in a new system can not open the new process

linux has a wai / waitpid recovery of the child for the parent resource

python will automatically recover zombie 

 

 

Common properties

# P.join () # wait for the child ends 
# p.terminate () # to terminate the process
name # print (p.name) # process
# print (p.is_alive ()) # is alive
# p.terminate () # as with the start command is sent to the operating system so there will be a delay
# Print (p.is_alive ())
# Print (p.pid)
# Print (p.exitcode) get the exit code #

 

 

 

 

Guess you like

Origin www.cnblogs.com/haojunliancheng/p/10956358.html