Day5: Application layer-CDN, TCP socket programming, UDP socket programming, summary

Come on! Steal bloggers!

0, killer application (killer application)

1. Network traffic accounted for a large proportion
2. Most attractive to users. For

example, Video Application: youtube, tiktok, iqiyi, Tencent movie...


 Video traffic: occupies most of the bandwidth of the Internet
 Challenge: Heterogeneity
 Different users have different capabilities (for example: wired access and mobile users; bandwidth-rich and limited users)
 Solution: distributed, application Infrastructure


Let's talk about the video again:

  •  Video: A sequence of images displayed at a fixed speed.  eg 24 images/sec

  •  Network video features:
     High bitrate: >10x for audio, high network bandwidth requirements
     Can be compressed
     More than 90% of network traffic is video

  • Digital image: Array of
    pixels  Each pixel is represented by several bits

  •  Coding: Use the redundancy between images and images to reduce the number of coded bits
     Spatial redundancy (within the image)
     Temporal redundancy (between adjacent images)
    An example is as follows:
    Insert picture description here
    frame frame
    Insert picture description here


0.1 Streaming service for storing video (see below)

Insert picture description here
Multimedia streaming service: DASH

  •  DASH: Dynamic, Adaptive Streaming over HTTP (dynamic and adaptive streaming technology on top of http)

  •  Server:
     Divide the video file into multiple blocks
     Each block is stored independently and encoded at different bit rates (8-10 types)
     Manifest file: Provides the URL of different blocks

  • Client :
     Obtain the notice file first.
     Periodically measure the bandwidth from the server to the client.
     Query the notice file and request a block at a time. The HTTP header specifies the byte range.
     If the bandwidth is sufficient, select the video block with the largest bit rate
     At different moments in the session, you can switch to request different coding blocks (depending on the available bandwidth at that time)

  •  "Smart" client: The client adaptively decides
    when to request a block (not to starve the cache or overflow)
     What encoding rate video block to request (when the bandwidth is sufficient, request a high-quality video block)
     Where to go to the request block (you can send a URL to a server close to you, or request to a server with high available bandwidth) I
    Insert picture description here
    understand too rough, I don’t know much


一、CDN (Content Distribution Networks)

 Challenge: How can the server stream video content (millions of video content) to millions of users simultaneously through the network?

  •  Option 1: A single, large super service center "megaserver"
     There are many hops on the path from the server to the client, and the bandwidth of the bottleneck link is small, resulting in a pause.
     The “two-eight rule” determines that the network is flooded with the same video at the same time Multiple copies of, low efficiency (high payment, waste of bandwidth, poor effect)
     Single point of failure, performance bottleneck
     Congestion comments on the surrounding network
    : quite simple, but this method is not scalable

  •  Option 2: Through CDN, deploy cache nodes across the network, store service content, provide services to users nearby, and improve user experience

    •  enter deep: (a deployment strategy "going deep into the masses")
      to deepen the CDN server into many access networks
       closer to users, large in number , close to users, difficult to manage
      Akamai, 1700 locations
    •  bring home: (another deployment strategy "squatting key")
      Deploy in a small number (about 10) of key locations , such as installing the server cluster near the POP (closer to several 1stISP POPs) Use
      leased lines to install the server cluster Connect
       Limelight

Insert picture description here
China Lanxun, CDN service provider. Do content acceleration services (streaming media on-demand, real-time multimedia, live broadcast, and live broadcast of Spring Festival Gala)


1. Give an example:

Netflix (translated as Netflix or Netflix, is a membership subscription streaming platform) bought Akamai's content acceleration service, and pre-deployed MadMen in the cache node (the dark brown node at the edge of the figure below).

  • When the user orders MadMen , (the little house on the left Where's MadMen?)
  • Then you will get a notice file manifest file.
  • In the notice file, you can know which deployed nodes can be broadcast on demand.
  • Therefore, the closest node with the least network congestion and the least traffic, that is, the best node, is selected first, and the video on demand (red arrow)
    Insert picture description here

Provide network acceleration services at the application layer and at the edge of the network.
Insert picture description here

2. CDN: "simple" content access scenario-a simple example to see the operation of CDN

Insert picture description here
This picture is messy, let me explain:

①: Bob browses the webpage of netcema.com, finds a little movie he likes (url is http://netcinema.com/6y7b23v, of course I haven't tried this url is it true) and clicked it.
②This URL goes to the local name server name resolution server agent
. ③Then the local name server finds the authoritative name server of netcinema level by level. The authoritative name server returns a redirected url "http://kKingCDN.com..." tells the local name server "You have to resolve this url again"
④Then the local name server goes to the authoritative name server of Zhao KingCDN, and got the departure from Bob (Customer) the closest is a cache node.
⑤ So Bob (client) knows the cache node closest to him from the local name server.
⑥Bob will request the streaming service of dash from the nearest cache node, and he can watch the small movie on the web page.


Now I am looking at a picture
Insert picture description here


One, TCP socket programming

1. Socket programming

  1. The application process uses the service provided by the transport layer to exchange messages, realize the application protocol, and realize the application
    TCP/IP: the application process uses the Socket API to access the transmission service
    Location: SAP (Socket) on the interface Mode: Socket API
  2. Goal : Learn how to build a C/S application program that can communicate with sockets. Socket: the door between distributed application processes, the end-to-end service interface provided by the transport layer protocol
    Insert picture description here

Two types of sockets for transport layer services:
3.  TCP: reliable, byte stream service
4.  UDP: unreliable (data UDP datagram) service

2. TCP socket

Socket: the portal
TCP service between the application process and the end-to-end transport protocol (TCP or UDP) : reliable transmission of byte streams from one process to another
Insert picture description here


3. TCP socket programming

The server runs first, waiting for the connection to be established

  • 1: The server process must be in a running state.
     Create a welcome socket (create a socket to return an integer, which is meaningless)
     (and then bind this integer) with the local port
     block the welcome socket and wait for the user's connection (if If no one connects, it will be blocked)
    (Create a bundle to wait, these are socket api functions)

The client actively establishes a connection with the server:

  • 2: Create a client local socket (implicitly bound to the local port)
     Specify the IP address and port number of the server process to connect to the server process
  • 3: When the connection request with the client comes, the
    server accepts the request from the client, unblocks the waiting, and returns a new socket, (connection socket value) (not the same as the welcome socket), and communicates with the client
     allows the server to communicate with the client Multiple client communication
     Use source IP and source port to distinguish different clients
  • 4: When the connection API call is valid, the client P establishes a TCP connection with the server
    Insert picture description here

4. Application examples of C/S mode:

Insert picture description here

First look at the two data structures , and then further explain the C/S socket interaction: TCP
Insert picture description here
Insert picture description here

When Server calls the bind function in the figure below, the parameter &sad is the structure of sockaddr_in{} above.
The &cad in the following accept() is also
Insert picture description here
an explanation of the structure of sockaddr_in{} . It takes a lot of talking . First, attach a video link to see Mr. Zheng’s explanation. Starting at 21min19s, it looks
like this:

At first, Server establishes a WelcomeSocket() and returns a random integer (for example, 8888). There is a parameter in the welcomeSocket function, which can represent whether the establishment is a TCP socket or a UDP socket, or even an IP socket.
At this time, the socket table entry is as follows

socket s_ip s_port c_ip c_port
8888 / / / /

And then, call the bind() function, bind the random value of socket 8888, bind Server's ip (1.1.1.1) and port number 80.
At the same time, assume that the Client's ip is 2.2.2.2 and the port is 777. The
table entries are updated as follows

s_socket s_ip s_port c_ip c_port
8888 1.1.1.1 80 / /

This entry is an entry used by the application layer and the transport layer.

and then, the Server calls connectionSocket =accept(welcomeSocket, &cad...) and waits for the 8888 socket, the connection request from the user, no client request, it is blocked...

Now, it is time for client to establish connection request.
Similarly, the client calls socket(PF_INET,...) to get a socket random integer (for example, 2222).
But the difference is that the client does not need to specifically bind, there will be an implicit bind. Compared with the server, the client does not need to specify a specific port to establish a socket connection.
Now the client also has a socket table entry.


c_socket c_ip c_port s_ip s_port
2222 2.2.2.2 777 / /

There is actually one more item in the table to indicate the status (currently invalid)

In the sixth step, the client calls connec() to initiate a connection establishment Request to the server. (A parameter of connect() indicates the binding relationship between ip:1.1.1.1 and port:80 in Server, so the c_socket table entry is updated when connect() is called)

c_socket c_ip c_port s_ip s_port
2222 2.2.2.2 777 1.1.1.1 80

At this time, the server socket responds, the connection is established, and accept() unblocks and returns a new socket integer value (for example, 8899). At
this time, the server socket has a new row with a valid value for the entry.

s_socket s_ip s_port c_ip c_port
8888 1.1.1.1 80 / /
8899 1.1.1.1 80 2.2.2.2 777

Explain:
here we fork the original welcomeSocket, get a new 8899 valid socket process, and go to deal with a socket process of the client.
The old process 8888 is still waiting on port 80, waiting for a new client process to request a connection.
The value of socket represents a conversational relationship!

Now that Socket Connection Established is easy to handle. Start to send, read, write reply through connectionSocket and clientSocket.
Finally, when I feel it’s time to leave, I close the
Insert picture description here
red arrow representing the interaction of the message.

Let’s take a look at some implementation codes.
Code explanations are even more troublesome.,, let’s take a look at Teacher Zheng’s eloquent explanations! (At 37min30s)
Insert picture description here

Insert picture description hereInsert picture description here

Insert picture description here

Two, UDP Socket programming

UDP: No connection between client and server

  • No handshake
  • The sender clearly specifies the IP address and port number of the target in each message
  • The server must extract the IP address and port number of the sender from the received packet

UDP: The transmitted data may be out of order or lost
Insert picture description here

1.Client/server socket interaction: UDP

After understanding the Socket programming of TCP above, wouldn't the Socket programming of UDP below be easy? (But the problem is that I still don’t understand the above)
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Three, summary

6

Guess you like

Origin blog.csdn.net/m0_46156900/article/details/113802102