amtoaer

晓风残月

叹息似的渺茫,你仍要保存着那真!
github
x
telegram
steam
nintendo switch
email

ByteDance Second Round Interview Question Record

Yesterday afternoon, I participated in two interviews. The first round with Kuaishou went smoothly and I passed. I thought the second round with ByteDance wouldn't be too difficult, but it turned out to be quite challenging... I will record the topics that I didn't know or wasn't clear about here for review (sad.

Do you have an understanding of CPU cache structure?#

Reference articles:

  1. Program Optimization: CPU Cache Basics - Zhihu

  2. CPU Cache Knowledge Related to Programmers - CoolShell

What problems can arise from having too many connections in the TIME_WAIT state? How to solve them?#

The port range is 0-65535, but there are not many available TCP ports after excluding those occupied by the system and other services. In this case, if a large number of connections remain in the TIME_WAIT state, it will prevent the use of these ports when other HTTP requests arrive. In other words, a continuous influx of a certain amount of high-concurrency short connections will cause the server to reject serving a portion of the clients due to insufficient port resources.

Solution:

  1. Solution to the Problem of Excessive TIME_WAIT - Cnblogs

  2. Handling Excessive TIME_WAIT in Linux TCP State - Zhihu

Do you understand HTTP persistent connections?#

Reference article:

HTTP Persistent Connections and Short Connections - Cnblogs

Common HTTP request headers?#

Reference article:

Detailed Explanation of Common HTTP Request Headers and Response Headers - Juejin

The server creates a cookie by sending an HTTP header named Set-Cookie as part of the Response Headers. Each Set-Cookie represents a cookie (if there are multiple cookies, multiple Set-Cookie headers should be written), and each attribute is in the form of name/value pairs (except for secure), separated by semicolons and spaces. The format is as follows:

Set-Cookie: name=value[; expires=GMTDate][; domain=domain][; path=path][; secure]

Reference article:

Common Local Storage - Cookie

What is the principle behind using the kill command to terminate a process?#

The kill command sends a signal to the specified process ID. The list of signals that can be sent is as follows:

❯ kill -l

HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM

TERM STKFLT CHLD CLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF

WINCH IO POLL PWR SYS RT<N> RTMIN+<N> RTMAX-<N>

Reference article:

Common Linux Network Commands - Cnblogs

What does the root node refer to in Golang garbage collection?#

Reference article: Golang Garbage Collection - Zhihu

Root set: The root objects, which are the first objects checked by the garbage collector. They include variables that can be determined by the program during compilation, variables on each goroutine's execution stack and pointers to the heap memory during execution.

What is the difference between WaitGroup and Channel for concurrency control in Golang?#

Going into the low-level implementation, WaitGroup is essentially a semaphore, and modifications to the semaphore use atomic operations from the atomic package. On the other hand, a channel itself is a thread-safe circular queue, and its production and consumption processes require locking. In other words, WaitGroup is lock-free, while channel has a lock. (Personal understanding)

Why does Golang use a circular queue for channels?#

I couldn't find a definitive answer, but I found this explanation in the article Illustrated Explanation of Go Channel Underlying Implementation - Cai Gang RyuGou's Blog:

As for why the channel uses a circular linked list as the cache structure, I personally think it is more convenient to locate the current send or recvx position and choose the send and recvx positions during the dynamic send and recv process of the cache list, as long as you rotate the list in order.

My personal understanding aligns with the author's.

When does Golang garbage collection perform STW (Stop The World)?#

Reference article:

Go: How Does the Garbage Collector Mark the Memory? - Medium

To tackle that potential issue, an algorithm of write barrier is implemented and will allow Go to track any pointer changes. The only condition to enable write barriers is to stop the program for a short time, also called "Stop the World":

In order to execute the marking, the write barrier needs to be enabled, which requires STW.

image

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.