Gin
Posted on October 5, 2024
|
What is Gin Web Framework? Gin is a lightweight, high-performance web framework for Go, inspired by Martini but with a focus on speed and efficiency.
Key Features of Gin Gin is packed with features that make web development in Go both enjoyable and efficient. Here are some of its standout features:
1. High Performance Gin is designed for speed. It outperforms many other Go frameworks by optimizing routing and minimizing middleware overhead, ensuring rapid request processing.
[Read More]Go's `http.ListenAndServe`
Posted on October 4, 2024
|
Implementation Overview The ListenAndServe function is part of Go’s standard library in the net/http package. Its primary purpose is to start an HTTP server that listens on a specified address and handles incoming requests.
func ListenAndServe(addr string, handler Handler) error { server := &Server{Addr: addr, Handler: handler} return server.ListenAndServe() } This function creates a Server instance and calls its ListenAndServe method.
Detailed Implementation The core logic is in the Server.ListenAndServe and Server.
[Read More]Network Interview
Posted on October 4, 2024
|
What is the OSI model? Physical Layer Data Link Layer Network Layer Transport Layer Session Layer Presentation Layer Application Layer Explain the difference between TCP and UDP. TCP (Transmission Control Protocol):
Connection-oriented Reliable, ensures all data is received Flow control and congestion control Slower than UDP Used for applications requiring high reliability (e.g., file transfer, email) UDP (User Datagram Protocol):
Connectionless Unreliable, doesn’t guarantee data delivery No flow control or congestion control Faster than TCP Used for applications that prioritize speed (e.
[Read More]Network Protocols
Posted on October 4, 2024
|
Transmission Control Protocol (TCP) TCP Principles and Mechanisms Key features:
Connection Establishment: Three-way handshake (SYN, SYN-ACK, ACK) Reliable Delivery: Acknowledgment and retransmission Flow Control: Sliding window mechanism Congestion Control: Slow start, congestion avoidance, fast retransmit, and fast recovery Ordered Data Transfer: Sequence numbers Error Detection: Checksum Example of TCP header:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgment Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | data | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ TCP Performance Characteristics Throughput:
[Read More]Operating System Interview
Posted on October 4, 2024
|
Explain the difference between a process and a thread. Process:
Independent execution unit Has its own memory space Heavyweight, more resources Isolated from other processes Thread:
Lightweight unit of execution within a process Shares memory space with other threads in the same process Less resource-intensive Can communicate easily with other threads in the same process How do processes and threads communicate Process communication methods:
Pipes and named pipes Shared memory Message queues Sockets Signals Thread communication methods:
[Read More]Subnet and Subnet
Posted on October 4, 2024
|
What is a Subnet? A subnet is a way to divide a large network into smaller, more manageable pieces. Think of it like dividing a big city into neighborhoods. Each subnet (neighborhood) has its own group of devices (houses), but all are still part of the same overall network (city).
What is a Subnet Mask? A subnet mask is a number used to help identify which part of an IP address belongs to the network (city) and which part identifies the device (house).
[Read More]Epoll
Posted on October 3, 2024
|
epoll (Linux): An Efficient I/O Multiplexing Mechanism epoll operates on an event-driven model, meaning it only notifies the application when an event occurs on a specific file descriptor, unlike select and poll which poll all descriptors regardless of activity. This drastically reduces overhead, especially when managing numerous connections.
Key Features and Functionality The core functionality revolves around three system calls:
epoll_create(size): Creates an epoll instance and returns an epoll file descriptor.
[Read More]MySQL's Transaction Isolation Levels
Posted on October 3, 2024
|
SQL Transaction Isolation Levels Transaction isolation levels define the degree to which the operations in one transaction are visible to other concurrent transactions and the types of reads and writes that are allowed.
Comparison Table Isolation Level Dirty Read Non-repeatable Read Phantom Read READ UNCOMMITTED Yes Yes Yes READ COMMITTED No Yes Yes REPEATABLE READ No No Yes SERIALIZABLE No No No Explanation of Isolation Levels 1. READ UNCOMMITTED This is the lowest isolation level.
[Read More]Eval and Evalsha
Posted on October 2, 2024
|
Overview EVAL and EVALSHA are Redis commands used to execute Lua scripts within the Redis server. They differ primarily in how they handle script loading and execution:
EVAL: This command takes the Lua script as an argument. Redis parses and hashes the script every time EVAL is called. This adds overhead, especially for frequently executed scripts.
EVALSHA: This command takes the SHA1 hash of the Lua script as an argument. Redis retrieves the script from its internal cache using this hash.
[Read More]Go Memory Allocation
Posted on October 2, 2024
|
How does Go handel memory allocation Memory Allocator Overview The Go memory allocator uses a hierarchical structure:
Heap: The main memory area where dynamically allocated objects reside. Spans: Large blocks of memory (usually 8KB) used to allocate objects. Objects: Individual allocated pieces of memory. graph TD Heap --> Span1[Span 1] Heap --> Span2[Span 2] Heap --> Span3[Span 3] Span1 --> Obj1[Object 1] Span1 --> Obj2[Object 2] Span2 --> Obj3[Object 3] Span2 --> Obj4[Object 4] Span3 --> Obj5[Object 5] Size Classes Go uses size classes to group objects of similar sizes.
[Read More]