- Echo Technology First Round
Kafka Multiple Partitions Ensuring Message Order
- Initially sending messages can be achieved by specifying key + single partition
- When multiple consumers process data, you can take modulo of the key and place it into queues, then use multiple threads to consume these queues. Queues maintain internal order
MySQL Without Isolation Levels - Can Multiple Threads Modify One Row?
- Isolation levels solve concurrent transaction problems like dirty reads, non-repeatable reads, phantom reads
- Without isolation, when multiple threads modify one row, if initial data is 0, thread 1 wants +1, thread 2 also wants +1, executing simultaneously results in 2, but for thread 1, I only wanted +1
Idempotency vs Thread Safety? Why Two Threads Modifying One Variable Doesn't Work
- Ensuring our program executes according to expected behavior when accessed by multiple threads means thread safety
- Two threads modifying one variable is possible, but results may not be what we want
Why Redis Uses Single Thread - Other Reasons Besides Locks?
- Lock overhead
- No CPU consumption due to context switching from multi-process or multi-threading
- Cannot utilize multi-core CPU performance, though this can be addressed by running multiple Redis instances on a single machine and binding Redis instances to CPU cores
Differences Between RPC and HTTP Access
Similarities: Both underlying communication uses sockets, both can implement remote calls, both can implement service-to-service calls
Differences:
- In terms of speed, RPC is faster than HTTP, though both use TCP, HTTP protocol information is often verboce
- In terms of complexity, RPC implementation is more complex, HTTP is relatively simple
- Use RPC for higher efficiency requirements, HTTP for flexibility and universality
- RPC uses long connections, HTTP uses short connections, higher efficiency
- RPC can compress messages for better traffic optimization
Issues with Direct MySQL Inventory Modification?
- No major issues, mainly concerned about MySQL being overwhelmed by high traffic volume
- Conventional method is setting inventory to non-negative values, using transactions, though this is slower
- Consider using optimistic locks, querying version, modifying based on version during updates
How Are Go Locks Implemented?
Mutex: Implemented through status and semaphores.
- Coroutine 1 locking sets lock=1
- Coroutine 2 locking sets waiter=1, indicating waiting
- Unlocking: Coroutine A releases semaphore to notify coroutine B that B can now lock
- Spinning: Failed lock attempts continue requesting lock without immediate blocking, implemented through CPU spinning, 30 clock cycles
- Universal Joy First Round
Common Go Packages, Functions in http and io
PHP Trait Function Priority
Parent class uses trait keyword, current class uses use to reference parent class
- Code reuse, equivalent to copying code
- Member priority: Current class > Trait > Parent class
Causes of MySQL Master-Slave Inconsistency With Same Configuration, Ignoring Network Factors
- Different loads on master and slave machines, threads too busy
- max_allowed_packet, master set larger, slave cannot execute large SQL
- Auto-increment keys inconsistent, different auto-increment steps
- Synchronization parameters not set
How Does Go Channel Ensure Thread Safety?
- Channel internally maintains a mutex to ensure thread safety
100W Users Watching Videos - How to Ensure Non-Repeating Content
PHP Extension Installation Steps, Compilation Commands
- wget extension.tar.gz download corresponding extension package and extract
- cd extension/ switch to extension directory
- /php/bin/phpize run phpize file under PHP installation directory, generates configure file in extension directory
- /configure --with-php-config=/php/bin/php-config run configuration, if only one PHP version on server no need to add --with-php-config parameter
- make && make install compile module
Differences Between Unique Index and Primary Key Index
- One table can only have one primary key index, multiple unique indexes
- Primary key index is always unique index, unique index is not primary key index
- Primary key can form referential integrity constraints with foreign keys, preventing data inconsistency
- HuoLaLa Second Round
Kafka Ensuring Sequential Message Writing
Producer send message has four parameters: partition number, timestamp, key, headers. We can specify key to ensure messages go to same partition
Effects of PHP while(true) Persistent Process
Cache Breakdown vs Cache Penetration
- Cache breakdown: Redis hot key expires
- Don't set expiration time for hot keys
- Mutual exclusion lock, add lock when no cache found to update cache
- Cache penetration: Redis + MySQL can't handle
- Parameter validation to prevent non-existent keys
- Bloom filter
- Cache empty values or default values
- Bilibili Department B Third Round
Interface Network Timeout Troubleshooting
- Code level:
- Check if downstream SQL queries timeout
- Database connections full, dead loops in code consuming CPU and memory
- Network level:
- ISP network issues
Differences Between Kafka Offset and MySQL Index
Kafka index:
- Offset index files establish mapping between message offset and physical address for quick positioning of message location
- Timestamp index files find offset information based on specified timestamp
- Haowei Lai First Round
Inter-Service Communication Implementation
Microservices must use inter-process communication mechanisms to interact. Microservice architecture has two categories: asynchronous messaging and synchronous request/response IPC mechanisms
Service Probe Implementation
- Liveness probe: Check if container running, restart pod if returns false
- Readiness probe: Check if container ready to accept HTTP requests, route traffic to pod if passes
Communication Methods Between Processes and Threads
Process communication:
- Pipe: usually parent-child process communication
- Semaphore: synchronization between processes and threads, also lock mechanism
- Shared memory: fastest IPC communication
- Socket: different process communication
- Message queue: linked list of messages stored in kernel with identifier
- Yingke First Round
LRU Implementation
MySQL ACID Implementation
- Atomicity: Transaction smallest execution unit, prevents splitting. Ensures actions complete entirely or don't execute at all through undo logs
- Consistency: Data remains consistent before and after transaction execution
- Isolation: Concurrent database access, one transaction doesn't interfere with others through isolation levels
- Durability: Committed transaction changes persistent even with database failure through redo logs
How Go sync.Map Achieves Concurrency Safety
Implementation separates read and write operations using read and dirty fields:
- Read data stored in read field, latest writes in dirty field
- Reads query read first, then dirty if not found, writes only to dirty
- Reading read doesn't require locking, reading/writing dirty requires locking
- misses field tracks read bypasses, syncs dirty to read after threshold
TCP TimeWait Generation and Prevention
Purpose:
- Guarantee server receives final ACK
- 2MSL ensures old packets disappear, preventing old packets in new connections
Prevention:
- Server socket option: so_reuseaddr
- Short connections to long connections
- Linux kernel parameter: net.ipv4.tcp_tw_reuse
- Xiaozhu Homestay
PHP Worker Thread Hang Recovery
- PHP-FPM hang usually due to thread busy, excessive requests, timeout
- Mainly modify config files, increase request limits, timeout settings
- Kill worker, master process automatically creates new worker
Single Machine Configuration for 1000 QPS
With 4-core 8GB machine:
- Maximum 4 simultaneous requests
- Assuming 30MB per process: 4048/30 = 135 (reserve some for MySQL)
- Assuming 200ms per request, 1000 QPS requires handling 200 requests simultaneously
- DiDi Second Round
Consistent Hashing
- Modulo 2^32, construct 0-2^32 hash ring
- Hash server IP or hostname as key
- Calculate key hash, find space clockwise to locate node
- Create virtual nodes to prevent uneven data distribution
- Node failure affects only part of data, other nodes remain functional
Different IDs Between Two Files A and B
- Divide and conquer, hash(id)%1000, split into 1000 small files a0...a99
- ID in a99 definitely exists in b99, convert to deduplication of small files
- Read a0, construct hash table, traverse b0, IDs not in a0 are unique
- Baidu First to Fifth Rounds
Team Management Understanding
Project Architecture Design Rationale
Bracket Matching Algorithm
String with square brackets [], curly braces {}, parentheses (), determine if they match