Python interview network programming and concurrency

Source: Internet
Author: User
Tags epoll

1. Describe the OSI seven layer protocol.

OSI Open System Interconnect Reference Model, which is theoretical, reference model
Layer Seven: layers--layer--layers--tier-I, Layer-layer, transport layer, data link layers, physical layer

2. What is C/s and b/s architecture?

C/S: client/server B/S: Browser/server

3. Briefly describe the process of three handshake and four wave waving.

Details

4. What is the ARP protocol?

ARP (address Resolution protocal) addresses resolution protocol, which is to put Ip->mac (you have heard ARP spoofing)

What is the difference between 5.TCP and UDP?

TCP is to confirm the arrival of packets, so do not lose the packet (data), the order is also good.
UDP does not confirm the arrival of packets, so it is possible to lose packets, although the order may be chaotic.
In addition to these:
1. TCP is a connection-oriented (three-time handshake), so stable, reliable, it is relatively slow
For example, the usual: file transfer, right-click, HTTP and so on are all TCP protocol
2. UDP is non-connected, so unstable, but relatively fast, high real-time
such as peacetime: What to do live broadcast, video call what

6. What are LAN and WAN?

LAN and WAN are two kinds of computer networks divided by size. The computer network within thousands of meters is referred to as the local area network, and the connection is more than 10-kilometer, called Wan, the Internet (intenet) is the largest WAN currently.

7. Why TCP protocol-based communication is more reliable than UDP-based communication

The reliable guarantee of TCP is the two-way mechanism of its three-handshake, which ensures that the data is verified and the reliability of the system is ensured. And UDP is not, after the UDP information issued, do not verify whether to reach the other side, so unreliable.

8. What is a socket? This paper describes the socket communication process based on TCP protocol.

In the field of computer communication, the socket is translated as a "socket", which is a convention or a way of communicating between computers. Through the socket convention, a computer can receive data from other computers, or it can send data to other computers.

basic flow of TCP socket communication

The ① server creates a ServerSocket object, specifies the port number, and the ServerSocket object waits for the client's connection request.
The ② client creates a socket object, specifies the host address and port number, and makes a connection request to the server.
The ③ server receives a connection request from the client, establishes a TCP connection, and then creates a socket object to communicate with the client's socket object.
The ④ server and the client create byte input stream and byte output stream respectively, and get the data from each other through byte input stream, and send data to each other through byte output.
⑤ when a party decides to end the communication, it sends the end message to the other party, and the other side closes the respective TCP connection after receiving the end message.
The ⑥serversocket object stops waiting for a connection request from the client.

9. What is a sticky bag? What is the cause of the sticky packet in the socket? What happens when a sticky bag occurs?   TCP是流式传送的 也就是连接建立后可以一直不停的发送 并没有明确的边界定义.发送端 - 接收端都存在这一个缓冲区 由接收方造成的粘包      当接收方不能及时接收缓冲区的包,造成多个包接收就产生了粘包         客户端发送一段数据,服务端只收了一小部分,服务端下次再收的时候还是从缓冲区拿上次         遗留的数据   由传输方造成的粘包     tcp协议中会使用Nagle算法来优化数据。发送时间间隔短,数据量小的包会一起发送,造成粘包What is the role of IO multiplexing?

Details

11. What is a firewall and what is the role?   它是一种位于内部网络与外部网络之间的网络安全系统。一项信息安全的防护系统,依照特定的规则,允许或是限制传输的数据通过。   防火可以使企业内部局域网(LAN)网络与Internet之间或者与其他外部网络互相隔离、限制网络互访用来保护内部网络。What are the differences between the Select, poll, and Epoll models?   selete : 有最大连接数 遍历         支持win   poll :    无最大连接数  遍历        支持win   epoll :  无最大连接数  事件通知   不支持win13. Describe the differences between process, thread, and association and the application scenario? # 进程 一个任务,进程之间内存隔离,一个进程修改数据不会影响其他进程(创建变量,修改变量值) # 线程 线程位于进程内 一个进程内至少有一个线程,线程之间资源共享.一个线程修改数据其他进程也会受影响所以有了锁的概念 # 协程 代码级别的保存状态 + 切换 多线程,协程用于IO密集型,如socket,爬虫,web,抢占cpu资源 多进程用于计算密集型,如金融分析,利用多核优势What the hell is that, Gil Lock?

Global interpreter Lock, yes, only one thread is working in a process

How do I use the thread pool and process pool in Python?
#Process Pool fromConcurrent.futuresImportProcesspoolexecutorImportTime,osdefPiao (name,n):Print("%s is piaoing%s"% (Name,os.getpid ()))#The process ID is printedTime.sleep (1) if __name__=="__main__": P= Processpoolexecutor (4)#Specify the maximum number of process pool processes     forIinchRange (10): obj= P.submit (Piao,"Alex%s"%i,i) Submit a task#thread PoolRom Concurrent.futuresImportThreadpoolexecutorImportTime,os,randomdefPiao (name,n):Print("%s is piaoing%s"% (Name,os.getpid ()))#The process ID is printedTime.sleep (Random.randint (1,3)) if __name__=="__main__": P= Threadpoolexecutor (4)#Specifies the maximum number of threads in a thread pool, without a control thread     forIinchRange (10): obj= P.submit (Piao,"Alex%s"%i,i)#Submit a Task
What is the role of threading.local?

Creates an object in which each thread sets the value data for the object to be isolated

17. How do I communicate between processes?

Queue

18. What is concurrency and parallelism?

Concurrency: Seems to be working at the same time, actually the CPU has been switching jobs

Parallel: Multiple tasks with multiple cores at the same time

19. What is the role of process lock and wire lock?

Process Lock: Prevents the process from operating a set of file systems at the same time

Thread Lock: Prevents multiple threads from modifying in-process data at the same time

20. Explain what is asynchronous non-blocking? # 非阻塞和阻塞的概念相对应,指在不能立刻得到结果之前也会立刻返回,同时该函数不会阻塞当前线程 # 异步的概念和同步相对。当一个异步功能调用发出后,调用者不能立刻得到结果。当该异步功能完成后, # 通过状态、通知或回调来通知调用者。21. What are the differences between routers and switches?

Routers: Connecting to external networks, with access to external lines

Switch: Connect the internal network, can not access the external line

22. What is domain name resolution?

When we enter the website domain name in the browser, we will request the DNS server to obtain the IP address of the domain name, and then go to the address change

23. How do I modify the local hosts file?

Win:c:\windows\system32\drivers\etc\hosts

Linux:/etc/hosts

Change by format

24. Producer Consumer model application scenarios and advantages? 生产者与消费者模式是通过一个容器来解决生产者与消费者的强耦合关系,生产者与消费者之间不直接进行通讯, 而是利用阻塞队列来进行通讯,生产者生成数据后直接丢给阻塞队列,消费者需要数据则从阻塞队列获取,实际应 用中,生产者与消费者模式则主要解决生产者与消费者生产与消费的速率不一致的问题,达到平衡生产者与消费者 的处理能力,而阻塞队列则相当于缓冲区。 # 应用场景 由一个线程生成订单,并将其放入队列中.由多个线程去处理 # 优势 平衡生产者与消费者的处理能力25. What is a CDN? CDN的全称是Content Delivery Network,即内容分发网络。 其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的瓶颈和环节,使内容传输的更快、更稳定。 通过在网络各处放置节点服务器所构成的在现有的互联网基础之上的一层智能虚拟网络,CDN系统能够实时地根 据网络流量和各节点的连接、负载状况以及到用户的距离和响应时间等综合信息将用户的请求重新导向离用户最近 的服务节点上。 其目的是使用户可就近取得所需内容,解决 Internet网络拥挤的状况,提高用户访问网站的响应速度。What is 26.LVS and what is the function? LVS的英文全称是Linux Virtual Server,即Linux虚拟服务器 LVS主要用于多服务器的负载均衡。它工作在网络层,可以实现高性能,高可用的服务器集群技术。它廉价,可把 许多低性能的服务器组合在一起形成一个超级服务器。它易用,配置非常简单,且有多种负载均衡的方法。它稳定 可靠,即使在集群的服务器中某台服务器无法正常工作,也不影响整体效果。另外可扩展性也非常好。What is 27.Nginx and what is the function? 处理静态文件 负载均衡 反向代理What is 28.keepalived and what is the function? Keepalived的作用是检测服务器的状态,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到, 并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工作正常后Keepalived 自动将服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的服务 器。What is 29.haproxy and what is the function? HAProxy是一个使用C语言编写的自由及开放源代码软件[ 1 ],其提供高可用性、负载均衡,以及基于TCP和HTTP 的应用程序代理。 HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理。HAProxy运行在当前 的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构 中, 同时可以保护你的web服务器不被暴露到网络上。 HAProxy实现了一种事件驱动, 单一进程模型,此模型支持非常大的并发连接数。多进程或多线程模型受内存限制 、系统调度器限制以及无处不在的锁限制,很少能处理数千并发连接。事件驱动模型因为在有更好的资源和时间管 理的用户空间(User - Space) 实现所有这些任务,所以没有这些问题。此模型的弊端是,在多核系统上,这些程 序通常扩展性较差。这就是为什么他们必须进行优化以 使每个CPU时间片(Cycle)做更多的工作。 包括 GitHub、Bitbucket[ 3 ]、Stack Overflow[ 4 ]、Reddit、Tumblr、Twitter[ 5 ][ 6 ]和 Tuenti[ 7 ]在内的知 名网站,及亚马逊网络服务系统都使用了HAProxy。 # 作用 负载均衡30. What is load Balancing? 负载均衡 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽、增加吞吐 量、加强网络数据处理能力、提高网络的灵活性和可用性。 负载均衡,英文名称为Load Balance,其意思就是分摊到多个操作单元上进行执行,例如Web服务器、FTP服务 器、企业关键应用服务器和其它关键任务服务器等,从而共同完成工作任务。 # 重点 拓展网络设备31. What are RPC and application scenarios? RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要 了解底层网络技术的协议。RPC协议假定某些传输协议的存在,如TCP或UDP,为通信程序之间携带信息数据。在 OSI网络通信模型中,RPC跨越了传输层和应用层。RPC使得开发包括网络分布式多程序在内的应用程序更加容 易。 RPC采用客户机 / 服务器模式。请求程序就是一个客户机,而服务提供程序就是一个服务器。首先,客户机调用进 程发送一个有进程参数的调用信息到服务进程,然后等待应答信息。在服务器端,进程保持睡眠状态直到调用信息 到达为止。当一个调用信息到达,服务器获得进程参数,计算结果,发送答复信息,然后等待下一个调用信息,最 后,客户端调用进程接收答复信息,获得进程结果,然后调用执行继续进行。 # 简单来说就是客户端与服务端并不直接通信,而是通过两个管道,多客户端通过一个管道向服务端发送消息,   每个客户端都有一个管道来接收信息32. Briefly describe the function and application of the Asynio module.

Details

33. Briefly describe the function and application of the Gevent module.

Details

The use and application of 34.twisted frame?

Details

Python interview network programming and concurrency

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.