2018 Written Interview Summary - Baidu Interview Notes

1. Why does redis have fast read and write rates and good performance

  • 1. Batch processing:
    When redis processes data, it is best to perform batch processing. Change the processing of one piece of data to multiple pieces at a time, and the performance can be doubled. The purpose of the test is to figure out the difference between batch processing and non-batch processing. From the test results, the performance difference is very large, so try to use batch processing during the development process, that is, send multiple pieces of data at a time to offset the network speed. influence.
  • 2. Network:
    Redis is greatly affected by the network during processing, so it is best to deploy it locally. If you deploy redis locally, you can get 10 to 20 times the performance. In the case of a cluster, the network hardware and network speed requirements must be high.
  • 3. Memory:
    Since I encountered a redis read timeout in the test environment, the troubleshooting reason is located on the Linux interactive partition. If there is not enough memory, linux may put some data of reids into the swap partition, resulting in very slow read speed and timeout. So be sure to reserve enough memory for redis to use.

2. What is the difference between @Controller and @RestController?

Official document:
@RestController is a stereotype annotation that combines @ResponseBody and @Controller.
Meaning:
@RestController annotation is equivalent to @ResponseBody + @Controller combined.

  • 1. If you just use @RestController to annotate the Controller, the method in the Controller cannot return the jsp page, the configured view resolver InternalResourceViewResolver does not work, and the returned content is the content in Return.
    For example: If it should have been to the success.jsp page, it will display success.
  • 2. If you need to return to the specified page, you need to use @Controller with the view resolver InternalResourceViewResolver.
  • 3. If you need to return JSON, XML or custom mediaType content to the page, you need to add the @ResponseBody annotation to the corresponding method.

Summary of advantages and disadvantages of redis

Advantages:
- 1. Excellent read and write performance-
2. Supports both AOF and RDB persistence methods-
3. Supports master-slave replication, automatically synchronizes data to slaves, and can separate read and write-
4. Rich data structure ;In addition to supporting value of type string, it also supports data structures such as string, hash, set, sort, edset, and list.
Disadvantages
Disadvantages:
- 1. Redis does not have automatic fault tolerance and recovery functions. The downtime of the host and slave will cause some read and write requests to fail in the front-end. It needs to wait for the machine to restart or manually switch the front-end IP to recover.
- 2. When the host is down, some data cannot be synchronized to the slave in time before the downtime. After the IP is switched, the problem of data inconsistency will be introduced, which reduces the availability of the system.
- 3. The master-slave replication of Redis adopts full replication. During the replication process, the host will fork a child process to take a snapshot of the memory, and save the memory snapshot of the child process as a file and send it to the slave. In this process, it is necessary to ensure that the host There is enough free memory. If the snapshot file is large, it will have a greater impact on the service capability of the cluster, and the replication process will be performed when the slave machine newly joins the cluster or when the slave machine and the host network are disconnected and reconnected, that is, network fluctuations will cause the host and the host. A full amount of data replication between slaves causes a lot of trouble for the actual system operation.
- 4. Redis is difficult to support online expansion, and online expansion will become very complicated when the cluster capacity reaches the upper limit. To avoid this problem, operation and maintenance personnel must ensure that there is enough space when the system goes online, which results in a great waste of resources.

There are several ways of dependency injection, which ones

The dependency injection mechanism reduces the dependencies between components, and also greatly improves the portability of components, which means that the opportunity for components to be reused will be more. There are three types of dependency injection
in spring ioc, namely:.
a, Interface injection;
b, setter method injection;
c, constructor injection;

http request header

An HTTP client program (such as a browser) must specify the request type (usually GET or POST) when sending a request to the server. The client may also choose to send other request headers if necessary. Most request headers are not required, with the exception of Content-Length. Content-Length must be present for POST requests.

Process of http request request?

The header of Http will wrap our request, such as the acceptable Accept (text/html) that is often set in AF -> domain name resolution, find the IP of the server according to the domain name -> initiate a 3-way handshake of TCP -> after establishing a TCP connection Initiate an http request –> the server responds to the http request, the browser gets the html code –> the browser parses the html code, and requests resources (such as js, css, pictures, etc.) in the html code –> the browser renders the page and presents it to the user

Every request will go through the client's application layer (http protocol) -> client's transport layer (tcp or udp protocol) -> client's network layer (ip protocol) -> client's link layer (network card, router, etc.) - > —————After dns analysis, through multiple isps (Internet service providers, mobile, China Unicom, telecommunications, etc.), various data exchanges, and found the server —————- the link layer of the server- > Network layer of server –> Transport layer of server –> Application layer of server. This request is complete.

HTTP status codes

The HTTP Status Code is a 3-digit code used to indicate the HTTP response status of the web server. It is defined by the RFC 2616 specification and extended by RFC 2518, RFC 2817, RFC 2295, RFC 2774, RFC 4918, etc.

Hierarchical traversal of binary tree

The idea of ​​level traversal of binary tree is realized by means of queue. Equivalent to breadth-first search, using queues (for depth-first search, using stacks).
If the root node is empty, return directly;
if the root node is not empty, add the root node to the queue, then judge whether the queue is empty, if not, dequeue the first node of the team, visit, and judge its left and right children Whether the node is empty, if not, it will be pushed into the queue.

quicksort

Divide the data to be sorted into two independent parts by one sorting, and all the data in one part is smaller than all the data in the other part, and then quickly sort the two parts of data according to this method. The whole sorting process can be Recursively, so that the entire data becomes an ordered sequence.

GET and POST

The difference between POST and GET
- 1. The principle is different:
generally, we enter a URL in the browser to access the website is a GET request; in the FORM form, you can specify the submission method as GET or POST by setting the Method, and the default is GET submission method . HTTP defines different ways to interact with the server, the most basic of which are four: GET, POST, PUT, DELETE, HEAD, where GET and HEAD are called safe methods, because HTTP requests using GET and HEAD do not produce any action . No action means that HTTP requests for GET and HEAD will not produce any results on the server. But the security method does not mean that no action is generated. The security method here only means that the information will not be modified. According to the HTTP specification, a POST may modify a request for a resource on the server.
- 2. The amount
of data transmitted by GET is small and cannot be larger than 2KB. The amount of data transmitted by POST is relatively large, and is generally unlimited by default.
- 3. Security and efficiency The
traditional comparison is that GET is very low security, while POST security is high. Because GET request data will be exposed in the address bar, but POST request will not. But the execution efficiency of GET is better than POST method. It can also be traced through our own website. The data submitted by GET, username and password will appear on the URL in plain text, which will give some people a chance. When others get your account number and password, the consequences will be unimaginable. It's suddenly creepy here, but when I saw the following story, I suddenly felt that the world was okay...
Summarize the difference between GET and POST in one sentence, GET is less secure than POST, and if it contains confidential information, it is recommended to use POST data submission method. When doing data query, it is recommended to use GET method; when doing data addition, modification, and deletion, it is recommended to use POST method

Difference between tcp and udp

Summary of the differences between TCP and UDP:
- 1. TCP is connection-oriented (such as dialing up to establish a connection to make a call); UDP is connectionless, that is, it does not need to establish a connection before sending data
- 2. TCP provides reliable services. That is, data transmitted over a TCP connection is error-free, not lost, not duplicated, and arrives in order; UDP does its best to deliver, i.e. does not guarantee reliable delivery

    1. Tcp realizes reliable transmission through checksum, retransmission control, serial number identification, sliding window, and acknowledgment. For example, when the packet is lost, the retransmission control can also be used to control the sequence of the packets that are out of order.
    1. UDP has better real-time performance and higher work efficiency than TCP, and is suitable for high-speed transmission and real-time communication or broadcast communication.
    1. Each TCP connection can only be point-to-point; UDP supports one-to-one, one-to-many, many-to-one and many-to-many interactive communication
    1. TCP requires more system resources, while UDP requires less system resources.

The difference between http: and https:

The data transmitted by the HTTP protocol is unencrypted, that is, in plain text. Therefore, it is very insecure to use the HTTP protocol to transmit private information. In order to ensure that these private data can be encrypted and transmitted, Netscape designed the SSL (Secure Sockets Layer) protocol for HTTPS was born to encrypt the data transmitted by the HTTP protocol.

Simply put, the HTTPS protocol is a network protocol constructed by the SSL+HTTP protocol that can perform encrypted transmission and identity authentication, and is more secure than the http protocol.

The main differences between HTTPS and HTTP are as follows:

    1. The https protocol needs to go to the ca to apply for a certificate. Generally, there are few free certificates, so a certain fee is required.
    1. http is a hypertext transfer protocol, information is transmitted in clear text, and https is a secure ssl encrypted transfer protocol.
    1. http and https use completely different connection methods and use different ports. The former is 80 and the latter is 443.
    1. The connection of http is very simple and stateless; the HTTPS protocol is a network protocol constructed by the SSL+HTTP protocol that can perform encrypted transmission and authentication, and is more secure than the http protocol.

TCP/IP protocol

TCP is a connection-oriented communication protocol. The connection is established through a three-way handshake. When the communication is completed, the connection must be removed. Since TCP is connection-oriented, it can only be used for end-to-end communication.
TCP provides a reliable data stream service, and uses the "positive acknowledgment with retransmission" technology to achieve transmission reliability. TCP also uses a method called "sliding window" for flow control. The so-called window actually represents the receiving capacity and is used to limit the sending speed of the sender.
If there are already sealed TCP packets in the IP packets, then IP will pass them 'up' to the TCP layer. TCP sorts packets and checks for errors, while implementing connections between virtual circuits. TCP packets include sequence numbers and acknowledgments, so out-of-order packets can be sequenced and corrupted packets can be retransmitted.
TCP sends its information to higher-level applications, such as Telnet servers and clients. Applications in turn send information back to the TCP layer, which then passes them down to the IP layer, device drivers and physical media, and finally to the receiver.
Connection-oriented services such as Telnet, FTP, rlogin, X Windows, and SMTP require a high degree of reliability, so they use TCP. DNS uses TCP in some cases (to send and receive domain name databases), but uses UDP to convey information about individual hosts.

Guess you like

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