Table of Contents
(3) Question: HTTP cache
Question: What does OPTION do? Give an example of using OPTION?
Q: Do you know http? Which layer of agreement? (Application layer)
(3) Question: How does the TCP protocol ensure reliability, and why is UDP unreliable?
HTTP 2 Improvement
References
Home headlines Come and take a look at the basic computer network interview questions that ByteDance frequently tests!

Come and take a look at the basic computer network interview questions that ByteDance frequently tests!

Apr 26, 2021 am 10:02 AM
ByteDance

This article will share with you some of ByteDance’s favorite front-end interview questions about computer networks. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Come and take a look at the basic computer network interview questions that ByteDance frequently tests!

Note: The (xx) number appearing in front of each question represents the frequency of this question. This computer network foundation is based on 30 front-end Questions and corresponding answers, reference links, etc. compiled from the interview. The content of the article is compiled by the person who got the Offer.

(3) Question: HTTP cache


HTTP cache is divided into strong cache and negotiation cache:

  • First verify whether the strong cache is available through Cache-Control. If the strong cache is available, then read the cache directly.

  • If not, then enter the negotiation cache phase and initiate an HTTP request. , the server checks whether the resource is updated by including the conditional request fields If-Modified-Since and If-None-Match in the request header:

    • If the resource is updated, then the resource and 200 are returned Status code

    • If the resource has not been updated, tell the browser to directly use the cache to obtain the resource

##( 5) Question: What are the commonly used status codes and usage scenarios of HTTP?


  • 1xx: Indicates that the protocol is currently in an intermediate state, and subsequent requests are required

  • 2xx: Indicates that the request is successful

  • 3xx: Indicates redirection status and requires re-request

  • 4xx: Indicates request message error

  • 5xx: Server-side error

Common status codes:

  • 101 Switch the request protocol from HTTP to WebSocket

  • 200 The request is successful and there is a response body

  • 301 Permanent redirection: Will be cached

  • ##302 Temporary redirection: Will not cache
  • 304 Negotiation cache hit
  • 403 Server access prohibited
  • 404 Resource not available Found
  • 400 Request Error
  • 500 Server Side Error
  • 503 Server Busy
Do you know what the 302 status code is? What 302 scenarios have you encountered when browsing the web?

And 302 means temporary redirection. This resource cannot be accessed temporarily, but it can still be accessed after a period of time. Generally, when accessing resources of a certain website requires permission, Users will be required to log in. After jumping to the login page and logging in, they can continue to access.

301 is similar, it will jump to a new website, but 301 represents that the resource of the accessed address has been permanently removed. This address should not be accessed in the future. Search engines will also use the new one when crawling. Replace this old one with the address. The returned address can be obtained from the location header of the returned response. The scenario of 301 is as follows:

    For example, jump from http://baidu.com to https://baidu.com
  • domain name Changed
  • (2) Question: Common HTTP request methods, their differences and uses?

http/1.1 specifies the following request method:

    GET: Universal acquisition of data
  • HEAD: Obtaining resources Meta information
  • POST: Submit data
  • PUT: Modify data
  • DELETE: Delete Data
  • CONNECT: Establish a connection tunnel, used for proxy servers
  • OPTIONS: Lists the request methods that can be performed on resources, often used across Domain
  • TRACE: Tracking request-response transmission path
()Q: What is your understanding of computer networks


Application layer, presentation layer, session layer, transport layer, network layer, data link layer, physical layer

(3 ) Q: What is HTTPS? Specific process

HTTPS establishes a security layer between HTTP and TCP. When HTTP communicates with TCP, it must first pass through a security layer, encrypt the data packet, and then The encrypted data packet is transmitted to TCP, and the corresponding TCP must decrypt the data packet before it can be transmitted to the HTTP above.

The browser transmits a client_random and encryption method list. After the server receives it, it passes it to the browser a server_random, encryption method list and digital certificate (including the public key), and then the browser performs legal verification on the digital certificate. , if the verification is passed, a pre_random is generated, and then encrypted with the public key and transmitted to the server. The server uses client_random, server_random and pre_random to encrypt the secret using the public key, and then uses this secret as the secret key for subsequent transmissions to encrypt and decrypt data. .

(4) Question: Three-way handshake and four-way wave

Why three-way handshake is necessary: ​​to confirm the sending and receiving capabilities of the other party.

Three-way handshakeThree-way handshake main process:

  • At the beginning, both parties are in CLOSED state, and then the server starts to listen to a certain port and enters the LISTEN state

  • Then the client actively initiates a connection, sends SYN, and then It becomes SYN-SENT, seq = x

  • After the server receives it, it returns SYN seq = y and ACK ack = x 1 (for the SYN sent by the client), it becomes After becoming SYN-REVD

  • , the client sends ACK seq = x 1, ack = y 1 to the server again, and becomes EASTABLISHED. When the server receives ACK, it also enters ESTABLISHED.

SYN requires peer confirmation, so the serialization of ACK needs to be increased by one. Anything that requires peer confirmation will consume one point of TCP message serialization

Why not twice?

Unable to confirm the client's receiving capabilities.

If the client sends a SYN message first, but it stays in the network, TCP will think that the packet has been lost, and then retransmit, and the connection will be established with two handshakes.

Wait until the client closes the connection. But if the packet arrives at the server later, the server will receive it, then send the corresponding data table, and the link will be established. However, the client has closed the connection at this time, resulting in a waste of link resources.

Why not four times?

More than four times are fine, but three times is enough

Waving four times

  • It is in the ESTABLISH state at the beginning, and then the client sends a FIN message with seq = p, and the state changes to FIN-WAIT-1

  • Server After receiving it, send ACK to confirm, ack = p 1, and then enter the CLOSE-WAIT state

  • After the client receives it, it enters the FIN-WAIT-2 state

  • After a while, wait for the data to be processed, send FIN and ACK again, seq = q, ack = p 1, enter the LAST-ACK stage

  • The client receives After FIN, the client enters TIME_WAIT (wait for 2MSL) after receiving it, and then sends ACK to the server ack = 1 1

  • After the server receives it, it enters the CLOSED state

The client still needs to wait for two MSLs at this time. If it does not receive a resend request from the server, it means that the ACK has arrived successfully. The wave ends and the client changes to the CLOSED state. Otherwise, the ACK is retransmitted.

Why do you need to wait for 2MSL (Maximum Segment Lifetime):

Because if you don’t wait, if the server still has many data packets to send to the client, and this When the client port is occupied by a new application, useless data packets will be received, causing data packet confusion. Therefore, the safest way is to wait until all data packets sent by the server are dead before starting the new application.

  • 1 MSL guarantees that the last ACK message from the active closing party in four waves can finally reach the peer

  • 1 MSL guarantees If the end does not receive ACK, then the retransmitted FIN message can reach

Why four times instead of three times?

**If it is three times, then the ACK and FIN of the server are combined into one wave. Such a long delay may prevent a TCP FIN from reaching the server, and then the client will continue to resend it. FIN

##References

  • https://zhuanlan.zhihu.com/p/86426969

Q: What should I do if the data transmission is completed during the interaction and I still don’t want to disconnect? How can I maintain it?


In HTTP, the Connection field of the response body is designated as keep-alive

Do you know anything about TCP sliding windows?


In the TCP link, for the sender and receiver, TCP needs to put the sent data into the

send buffer area, and put the received data into Receive buffer area. There are often situations where the sender sends too much and the receiver cannot digest it, so flow control is needed, which is to control the sending of the sender through the size of the receive buffer. If the other party's receiving buffer is full, it cannot continue to send. This flow control process requires maintaining a sending window at the sending end and a receiving window at the receiving end.

TCP sliding windows are divided into two types:

sending window and receiving window.

References

  • https://juejin.im/post/5e527c58e51d4526c654bf41#heading-38

Q: What is the difference between WebSocket and Ajax


##Essence Different Ajax, which is asynchronous JavaScript and XML, is a web development technology for creating interactive web applications

websocket is a new protocol of HTML5 that implements Real-time communication between browser and server

Different life cycles:

  • Websocket is a long connection, and the session is always maintained

  • ajax will be disconnected after sending and receiving

Scope of application:

  • ##websocket is used for front-end and back-end real-time interactive data

  • ajax non-real-time

Initiator:

    ##AJAX client initiated
  • WebSocket server and client push each other
Do you know WebSocket?

Long polling and short polling, WebSocket is long polling.

For example, in an e-commerce scenario, the inventory of goods may change, so it needs to be reflected to the user in time, so the client will keep sending requests, and then the server will keep checking for changes, regardless of Regardless of the change, everything is returned. This is short polling.

The performance of long polling is that if there is no change, it will not return, but wait for the change or timeout (usually more than ten seconds) before returning. If there is no return, the client does not need to keep sending requests. So the pressure on both sides is reduced.

Reference link

    https://www.jianshu.com/p/3fc3646fad80
How to implement long connection in HTTP? At what point does it time out?

By setting Connection: keep-alive in the header (request and response header), the HTTP1.0 protocol is supported, but it is turned off by default. From the HTTP1.1 protocol onwards, the connection defaults to Long connection

    HTTP generally has the httpd daemon, in which you can set the keep-alive timeout. When the tcp link is idle for more than this time, it will be closed. You can also set the timeout in the HTTP header. Time
  • TCP's keep-alive contains three parameters, which can be set in net.ipv4 of the system kernel: When the TCP connection is idle and tcp_keepalive_time is idle, a detection packet will occur. If no ACK is received from the other party, it will be sent again every tcp_keepalive_intvl until tcp_keepalive_probes is sent, and the link will be discarded.
    • tcp_keepalive_intvl = 15
    • tcp_keepalive_probes = 5
    • tcp_keepalive_time = 1800
  • In fact, HTTP does not have long and short links, only TCP does. TCP long connections can reuse a TCP link to initiate multiple HTTP requests, which can reduce resource consumption, such as requesting HTML at one time , you may also need to request subsequent JS/CSS/images, etc.

Reference link

    https://blog .csdn.net/weixin_37672169/article/details/80283935
  • https://www.jianshu.com/p/3fc3646fad80
Question: The difference between Fetch API and traditional Request


    fetch conforms to the separation of concerns, uses Promise, the API is richer, and supports Async/Await
  • The semantics are simple and more semantic
  • You can use isomorphic-fetch, isomorphism is convenient

Reference resources

    https://github.com/camsong/blog/issues/2
  • ##(2) Question: What types of files can generally be sent by POST, and data processing issues


Text, pictures, videos, audio, etc. are all acceptable
  • text/image/audio/ or application/json etc.
  • Question: How does TCP ensure effective transmission and congestion control principles.


tcp is a connection-oriented, reliable, transport layer communication protocol
  • Reliability is reflected in: stateful, Controllable

Stateful means that TCP will confirm which messages have been sent, which messages have been received by the receiver, and which ones have not been received, ensuring that data packets arrive in order, and no packets are allowed. Error
  • Controllable means that if packet loss occurs or the network condition is poor, it will jump to its own behavior, reduce the sending speed or resend
  • So the above can ensure the effective transmission of data packets.

Congestion Control Principle

The reason is that the entire network environment may be particularly poor and packet loss is easy, so the sender should pay attention.

Mainly use three methods:

Slow start threshold congestion avoidance
  • Fast retransmission
  • Quick reply
Slow start threshold congestion avoidance

For congestion control, TCP Mainly maintains two core states:

Congestion window (cwnd)
  • Slow start threshold (ssthresh)
  • Use the congestion window at the sender to control the size of the send window.

Then a relatively conservative slow start algorithm is used to slowly adapt to the network. During the initial transmission period, the sender and receiver will first establish a connection through a three-way handshake to determine the size of their respective receiving windows, and then Initialize the congestion window of both parties, and then double the size of the congestion window after each round of RTT (receiver and transmit delay) until the slow start threshold is reached.

Then start congestion avoidance. The specific method of congestion avoidance is to double the congestion window in each previous round of RTT, and now add one in each round.

Fast retransmission

During the TCP transmission process, if packet loss occurs, the receiving end will send a repeated ACK, such as 5 packets are lost, 6 and 7 are reached, and then the receiving end will send the ACK of the fourth packet for 5, 6, and 7. At this time, the sending end receives 3 repeated ACKs. When it realizes that the packet is lost, it will Retransmit immediately without waiting for RTO (timeout retransmission time)

Selective retransmission: optionally add the SACK attribute to the message header, mark those packets that have arrived through the left edge and right edge, and then Retransmit undelivered packets

Quick recovery

If the sender receives 3 duplicate ACKs and discovers packet loss, it feels like now The network condition has entered the congestion state, then it will enter the rapid recovery phase:

  • will reduce the congestion threshold to half of the congestion window

  • Then the congestion window size becomes the congestion threshold

  • Then the congestion window increases linearly to adapt to the network conditions

Question: What does OPTION do? Give an example of using OPTION?


Aims to send a probe request to determine what constraints a request for a certain target address must have, and then send the real request according to the constraints.

For example, pre-checking for cross-domain resources is sent first using the HTTP OPTIONS method. Used to handle cross-domain requests

Q: Do you know http? Which layer of agreement? (Application layer)


  • Flexible and scalable, except for the stipulations that spaces separate words and newlines separate fields, there are no other restrictions. It can not only transmit text, but also Transmit any resources such as pictures and videos

  • Reliable transmission, based on TCP/IP, so it inherits this feature

  • Request-response, there is There are responses

  • Stateless, each HTTP request is independent, irrelevant, and does not need to save context information by default

Disadvantages:

  • Clear text transmission is not safe

  • Reusing a TCP link will cause peer congestion

  • None In a long connection scenario, a large amount of context needs to be saved to avoid transmitting a large amount of repeated information

Q: OSI seven-layer model and TCP/IP four-layer model


OSI seven-layer model

  • Application Layers

  • Presentation layer

  • Session layer

  • Transport layer

  • Network layer

  • Data link layer

  • Physical layer

TCP/IP four-layer concept:

  • Application layer: application layer, presentation layer, session layer: HTTP

  • Transport layer: Transport layer: TCP/UDP

  • Network layer: Network layer: IP

  • Data link layer: Data link layer, physical layer

(3) Question: How does the TCP protocol ensure reliability, and why is UDP unreliable?


  • TCP is a connection-oriented, reliable, transport layer communication protocol

  • UDP is a connectionless transport layer Communication protocol, inherits IP characteristics, and is based on datagram

Why is TCP reliable? The reliability of TCP is reflected in the stateful and controlled

  • which will accurately record which data was sent, which data was received by the other party, and which was not received, and ensures that the data packets arrive in order. No mistakes are allowed, this is stateful

  • When it realizes that a packet has been lost or the network environment is poor, TCP will adjust its behavior according to the specific situation, control its own sending speed or restart This is controllable

On the contrary, UDP is stateless and uncontrollable

HTTP 2 Improvement


Improved performance:

  • Header compression

  • Multiple channel multiplexing

  • Server Push

References


  • ##https://juejin.im/post/5d032b77e51d45777a126183


For more programming-related knowledge, please visit:

Programming Video! !

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ByteDance's video editing app CapCut's global user spending exceeds US$100 million ByteDance's video editing app CapCut's global user spending exceeds US$100 million Sep 14, 2023 pm 09:41 PM

CapCut, a creative video editing tool owned by ByteDance, has a large number of users in China, the United States and Southeast Asia. The tool supports Android, iOS and PC platforms. The latest report from market research agency data.ai pointed out that as of September 11, 2023, CapCut’s total user spending on iOS and Google Play has exceeded US$100 million (notes on this site: currently about 7.28 billion), successfully surpassing Splice (ranked first in the second half of 2022) and becoming the world's most profitable video editing application in the first half of 2023, an increase of 180% compared with the second half of 2022. As of August 2023, 490 million people around the world are using CapCut through iPhone and Android phones. da

Bytedance model large-scale deployment actual combat Bytedance model large-scale deployment actual combat Apr 12, 2023 pm 08:31 PM

1. Background introduction In ByteDance, applications based on deep learning are blooming everywhere. Engineers pay attention to model effects but also need to pay attention to the consistency and performance of online services. In the early days, this usually required algorithm experts and engineering experts to work together and work closely together to complete. This mode has relatively high costs such as diff troubleshooting and verification. With the popularity of the PyTorch/TensorFlow framework, deep learning model training and online reasoning have been unified. Developers only need to pay attention to the specific algorithm logic and call the Python API of the framework to complete the training verification process. After that, the model can be easily serialized and exported. , and the reasoning work is completed by a unified high-performance C++ engine. Improved developer experience from training to deployment

Accelerate diffusion model, generate SOTA-level images in the fastest 1 step, Byte Hyper-SD is open source Accelerate diffusion model, generate SOTA-level images in the fastest 1 step, Byte Hyper-SD is open source Apr 25, 2024 pm 05:25 PM

Recently, DiffusionModel has made significant progress in the field of image generation, bringing unprecedented development opportunities to image generation and video generation tasks. Despite the impressive results, the multi-step iterative denoising properties inherent in the inference process of diffusion models result in high computational costs. Recently, a series of diffusion model distillation algorithms have emerged to accelerate the inference process of diffusion models. These methods can be roughly divided into two categories: i) trajectory-preserving distillation; ii) trajectory reconstruction distillation. However, these two types of methods are limited by the limited effect ceiling or changes in the output domain. In order to solve these problems, the ByteDance technical team proposed a trajectory segmentation consistent method called Hyper-SD.

Xiaomi Byte joins forces! A large model of Xiao Ai's access to Doubao: already installed on mobile phones and SU7 Xiaomi Byte joins forces! A large model of Xiao Ai's access to Doubao: already installed on mobile phones and SU7 Jun 13, 2024 pm 05:11 PM

According to news on June 13, according to Byte's "Volcano Engine" public account, Xiaomi's artificial intelligence assistant "Xiao Ai" has reached a cooperation with Volcano Engine. The two parties will achieve a more intelligent AI interactive experience based on the beanbao large model. It is reported that the large-scale beanbao model created by ByteDance can efficiently process up to 120 billion text tokens and generate 30 million pieces of content every day. Xiaomi used the beanbao large model to improve the learning and reasoning capabilities of its own model and create a new "Xiao Ai Classmate", which not only more accurately grasps user needs, but also provides faster response speed and more comprehensive content services. For example, when a user asks about a complex scientific concept, &ldq

Shenzhen Bytedance Houhai Center has a total construction area of ​​77,400 square meters and the main structure has been topped out Shenzhen Bytedance Houhai Center has a total construction area of ​​77,400 square meters and the main structure has been topped out Jan 24, 2024 pm 05:27 PM

According to the Nanshan District Government’s official WeChat public account “Innovation Nanshan”, the Shenzhen ByteDance Houhai Center project has made important progress recently. According to the China Construction First Engineering Bureau Construction and Development Company, the main structure of the project has been capped three days ahead of schedule. This news means that the core area of ​​Nanshan Houhai will usher in a new landmark building. The Shenzhen ByteDance Houhai Center project is located in the core area of ​​Houhai, Nanshan District. It is the headquarters office building of Toutiao Technology Co., Ltd. in Shenzhen. The total construction area is 77,400 square meters, with a height of about 150 meters and a total of 4 underground floors and 32 above ground floors. It is reported that the Shenzhen ByteDance Houhai Center project will become an innovative super high-rise building integrating office, entertainment, catering and other functions. This project will help Shenzhen promote the integration of the Internet industry

My ears are right, the sound is too real, the Seed-TTS technology of Byte Beanbao speech synthesis is revealed My ears are right, the sound is too real, the Seed-TTS technology of Byte Beanbao speech synthesis is revealed Jun 26, 2024 pm 08:37 PM

Seed-TTS is a large-scale speech generation model recently released by the ByteDance Doubao model team. , the speech it generates is almost **no different** from real people, and even pronunciation **defects** can be generated, especially in terms of learning to imitate human speech, with both **fidelity** and **fluency** **Outstanding performance. For example, if you provide a piece of speech to Seed-TTS, it can generate a new speech based on the text, and bring the sound characteristics of the original material. Original material (Prompt): Chinese voice generated by Seed-TTS: Suddenly, there was laughter around me. I looked at them, straightened my chest with high spirits, shook my slightly fleshy arms, and chuckled: "The flesh on my body is to cover up my overwhelming charm, otherwise

NUS and Byte collaborated cross-industry to achieve 72 times faster training through model optimization, and won the AAAI2023 Outstanding Paper. NUS and Byte collaborated cross-industry to achieve 72 times faster training through model optimization, and won the AAAI2023 Outstanding Paper. May 06, 2023 pm 10:46 PM

Recently, the top international artificial intelligence conference AAAI2023 announced the selection results. The CowClip technical paper collaborated by the National University of Singapore (NUS) and ByteDance Machine Learning Team (AML) was shortlisted for Distinguished Papers (Distinguished Papers). CowClip is a model training optimization strategy that can increase model training speed by 72 times on a single GPU while ensuring model accuracy. The relevant code is now open source. ​Paper address: https://arxiv.org/abs/2204.06240​Open source address: https://github.com/bytedance/LargeBatchCTR​AAA

PICO 4 sales are far below expectations, and news reports that ByteDance will cancel the next-generation VR headset PICO 5 PICO 4 sales are far below expectations, and news reports that ByteDance will cancel the next-generation VR headset PICO 5 Dec 15, 2023 am 09:34 AM

According to news from this website on December 13, according to The Information, ByteDance is preparing to ax its PICO new generation VR headset PICO5 because the sales of the current PICO4 are far lower than expected. According to an article by EqualOcean in October this year, ByteDance is said to be gradually shutting down PICO and abandoning the Metaverse field. The article pointed out that Bytedance believed that the hardware field in which PICO was located was not its expertise, its performance in the past few years had not met expectations, and it lacked hope for the future. At that time, the relevant person in charge of ByteDance responded to the rumors about "gradually abandoning the PICO business" responded, saying the news was untrue. They stated that PICO's business is still operating normally and that the company will invest in extended reality for the long term.