Reborn not to be a beast of burden, I set the rules.
Chapter 55 If Penguins Want to Do It
Teacher Zhang continued drawing: "Add a connection pool. Build a batch of connections in advance, and whoever needs one can borrow one and return it after use. This way, a new connection won't be created for every request. If we achieve this, we can handle up to three thousand people." He then marked another number.
"Adding an index to frequently used query fields can reach four thousand." Another index was added above that.
Ye Ming asked, "What about the text files? Is there still room for optimization?"
Teacher Zhang glanced at him: "How big is your text file now?"
"Eight hundred events. We'll start with five hundred, and the team will continue writing content, so we'll reach three thousand soon."
Teacher Zhang nodded: "Three thousand events, a few hundred KB of plain text. Even if it gets to ten thousand later, it'll only be one or two MB. Your server has at least 1 GB of memory, so this amount is not a problem at all."
Ye Ming pressed further, "Besides loading the file into memory, are there any other optimizations we can do?"
Teacher Zhang thought for a moment and said, "When there are many events, you need to consider the issue of 'hot topics.' Not all events are triggered at the same frequency."
Some events may be triggered tens of thousands of times a day, while others may only be triggered once every few days.
For those high-frequency events, you can cache the calculation results so you don't have to recalculate them every time.
He drew another box on the whiteboard and labeled it "Calculation Result Cache": "This is called 'Hot Event Result Cache.' It's different from your text file loading; one solves the I/O problem, and the other solves the CPU computation problem. They're two different things."
Ye Ming wrote all of this down: "Then how do we determine which events are trending?"
Teacher Zhang laughed: "You'll know once it's online and running. Look at the logs; see which events are triggered most frequently, and which events cause the server CPU to spike the highest. The data will tell you the answer. Tech people can't rely on guesswork; they have to rely on data."
Ye Ming nodded, then asked, "What about the rankings? How do you deal with the pressure on the rankings?"
Teacher Zhang continued drawing: "Make the leaderboard a static page, updating it every five minutes. When users access it, it directly reads the static file, without needing to query the database. This way, the access pressure on the leaderboard is eliminated."
Ye Ming pressed further, "Isn't five minutes too slow? The data users see isn't real-time."
Teacher Zhang glanced at him: "Does your game need real-time rankings?"
Do players care about their ranking, or about "I've improved since yesterday"?
Once you figure this out, you'll know whether five minutes is enough.
Often, what users want isn't absolute real-time, but rather "the appearance of real-time."
Ye Ming paused for a moment, then wrote down those words.
Ye Ming then asked, "Where should the static page for the leaderboard be hosted? Can't it be hosted on our own server?"
Teacher Zhang nodded: "Just put it on your own server. When users access it, it reads the static file directly, which reduces the pressure a lot."
Ye Ming pressed further, "What if the traffic gets even higher? What if the static pages can't handle it?"
Teacher Zhang smiled and drew several more boxes on the whiteboard, connecting them into a diagram: "Do load balancing."
Add a distributor in front and connect multiple servers behind it.
The user's request first goes to the dispatcher, which then decides which server to hand it over to for processing.
This reduces the load on each server, increasing the overall bandwidth capacity.
Ye Ming stared at the whiteboard for a while: "What about the user data? For example, if a user logs in, and the next request is redirected to a different server, won't it be lost?"
Teacher Zhang smiled: "You've hit the nail on the head. That's why we need to separate the user sessions and put them in Redis."
Redis is an in-memory database with extremely fast read and write speeds.
All servers share the same session data, so users can read their login status regardless of which machine they are assigned to.
Ye Ming pressed further: "Is Redis also stored in memory? Then what's the difference between it and MySQL?"
Teacher Zhang drew another box on the whiteboard and labeled it Redis: "MySQL is a hard drive database. Data is stored on the hard drive. It is slow to read and write, but it has a large capacity and is persistent."
Redis is an in-memory database where data resides in memory, making read and write speeds dozens of times faster, but it has a small capacity and data is lost when power is off.
Therefore, each has its own function. MySQL stores persistent data, while Redis stores temporary sessions and cache.
Ye Ming wrote all of this down, then asked, "What about the event database? It's shared across multiple servers, so each server needs a copy?"
Teacher Zhang nodded: "That's right. The event library is a text file, and a copy needs to be placed on each server. It needs to be synchronized when updating, which is a bit troublesome, but it's not impossible."
Ye Ming pressed further, "What about the database? Are multiple servers sharing a single MySQL instance?"
Teacher Zhang shook his head: "When MySQL can't handle the load, we have to split it up. We do read-write separation, with the master database handling writes and the slave database handling reads."
Data from the master database is synchronized to the slave database in real time. The write pressure is concentrated on one machine, while the read pressure is distributed across multiple machines.
This way, even with a large volume of data read, it can handle the load.
Ye Ming wrote all of this down, then asked, "Are the master database and slave databases on different servers?"
Teacher Zhang nodded: "Of course. There's one master database, and several slave databases can be connected. If the master database fails, the slave databases can take over. That's called high availability."
Ye Ming wrote all of this down, then asked, "What about CDN? What's the difference between it and load balancing?"
Teacher Zhang smiled and said, "CDN solves the bandwidth and latency problems. You send your static files to CDN service providers, such as Wangsu and ChinaCache, and they help you distribute them to nodes all over the country."
When a user accesses the system, data is retrieved from the nearest available source, without having to go through your single-core Xeon processor.
Load balancing addresses server load issues, while CDN addresses network transmission issues. They are two different things.
He paused, then added, "But that's all for later. Right now, focus on getting that single-core Xeon running smoothly."
Ye Ming wrote all of this down and then asked, "Teacher Zhang, following this line of thought, how much power can my server actually handle?"
Teacher Zhang thought for a moment: "With connection pooling, indexing, hotspot caching, and static leaderboards, your single-core Xeon machine can easily handle 8,000 to 10,000 concurrent users. With CDN, it can reach 20,000 to 30,000. Beyond that, we'll need load balancing and read/write separation. For a pure text game, 20,000 to 30,000 concurrent users translates to over 400,000 daily active users."
Ye Ming wrote all these numbers down in his notebook.
After finishing his lecture, Teacher Zhang put down his pen, turned around, and looked at him: "Now you need to think about a question."
Ye Ming looked up.
"What will you do if Tencent wants to make your game?"
Ye Ming remained silent for a few seconds.
"Teacher Zhang, I've been thinking about this problem." He paused, "I have some ideas now, but they're not fully formed yet. I'll think about them some more and then come back to ask you for advice."
Teacher Zhang glanced at him and nodded: "Okay, think it through before you come back."
He patted Ye Ming on the shoulder: "Go back and digest all of this. Come to me anytime if you have any questions."
Ye Ming put away his notebook and USB drive, stood up, and said, "Thank you, Teacher Zhang."
Teacher Zhang saw him to the door: "You have this energy, don't lose it."
Ye Ming nodded and walked out of the office. Sunlight streamed in from the window at the end of the corridor, falling onto the floor.
He walked slowly, his mind still replaying Teacher Zhang's last words.
What would you do if the penguins wanted to do it?
He recalled the incident on the screen earlier, and that night.
He needs to create a hidden achievement for that event.
It's not for the players, it's for her.
Unbeknownst to him, Xu Wei was still sitting in the computer lab of the Computer Association, writing about events absentmindedly, occasionally glancing at his empty seat.
You'll Also Like
-
American Comics: From Map Editor to Immortal Gods
Chapter 196 37 minute ago -
Honkai Impact Simulation, let me lead you to MVP!
Chapter 385 37 minute ago -
Konoha: Starting with the Tenseigan, taking over Team 7
Chapter 365 37 minute ago -
Shinji Ikari, the pilot of Unit-01 during the Spirit Awakening Era
Chapter 153 37 minute ago -
From Gotham to Night City, my infamy is known to all.
Chapter 289 37 minute ago -
Female Swordsman Training Dojo
Chapter 295 37 minute ago -
In this chaotic world of vying for power, I can become stronger by marrying a wife.
Chapter 76 37 minute ago -
Transmigrated into a fat wife, farming, raising children, and picking up husbands
Chapter 182 37 minute ago -
A four-year-old medical prodigy descended to the mortal realm, and the entire capital sought her tre
Chapter 242 37 minute ago -
Five cubs clung to her; the wicked woman was being targeted.
Chapter 83 37 minute ago