The combination of games and Weibo, the design of a microblog background and front-end (based on mysql ). (1)

Source: Internet
Author: User

Inscription-I dare not say anything about Weibo design, but there are still some differences between the integration of Weibo and the design of Weibo separately in the game. I have some experience and share it with you. I hope you can stay away from it, I did not waste my time on the road.

At present, many games have been added to the Weibo system. Of course, those games are supported by mature Weibo backend services. To implant Weibo, you only need to add some features of the game module to the game. I have never thought about designing Weibo.

About half a year ago, my boss told me that I wanted to implant my microblog into the game. I didn't comment on this idea, but my boss was so keen to do it, so I had to stick my head to it. the first step is to check the information. However, there are only a small amount of online information about Weibo's technical details, but some advertisement articles will mention that xx products use XX Technology for Weibo. this is far from the actual operation. later, I decided to start with data storage and select a data storage technology. of course, I don't know about Sina Weibo and QQ Weibo, but our games are all in MySQL. At that time, online data showed that it was very inefficient to use relational databases for Weibo, noSql is becoming more and more eye-catching with the rise of Weibo. cassandra was proposed at that time, so I had a rough understanding of this stuff, and I was not very familiar with it. The boss came and asked me to continue using MySql for the most important and simplest reason, that is, our company has no experience in using NoSql. The boss thinks it is not enough time for us to launch our products as soon as I start using NoSql. in the eyes of the boss, our Weibo positioning is limited Simple functions do not require the rich functions of Sina and QQ. (In fact, Weibo has solved the simplest functions, and there are no technical barriers to other things that are icing on the cake ). well, I can only design the Weibo System Based on MySql. Since MySql has already accumulated technical expertise, I will continue to design the Weibo architecture. To be honest, in the face of such mature products as QQ and Sina, let me design a Weibo system. I am a little scared at the beginning. Later on, I think I am also numb. In fact, I am the only one in this company. My boss really trusts me. I'm flattered, but there is a kind of conflict in my subconscious: Can I do this myself? Why do I have to finish it myself in a short time? I understand that the boss is under pressure from him, but there are some things that I think are not sweet.

Next, let's talk about the experiences in architecture. The first thing I face is the access to a large amount of data. For example:

Is the number of followers of a person capped?

This is obviously required, but what is the upper limit? For a small company like ours, it is impossible for players to reach hundreds of millions. So I can save the number of followers of each Weibo user to an int, but if a world-class product, this quantity must be carefully considered.

Is a message pushed by a fan?

From this seemingly simple question, let me talk about the architecture of our Weibo product:

The background must be connected to the web, and the information of web users and in-game users must be interconnected. Second, intercommunication of cross-server information within the game. Many games actually do little work in cross-server mode, and so do our games (because in general, cross-server operations are not necessary to be designed, so many companies are too lazy to spend time doing it ). In addition, although our strength cannot be met immediately after user A sends A message to his fans, our goal is to shorten the time as much as possible. However, if A person has A large number of fans, in this example, we need to traverse and check whether each fan is online, send messages online, and Mark offline so that new information can be seen after the User goes online. Because we use MySql, this data is actually a test of how you design tables. The database query performance is only 2000 or 3000 concurrent queries for the servers we can afford. Besides, our other servers are also on a physical server, which makes it impossible for me to use full load performance. In fact, at the time of design, I was a little desperate. On the one hand, I tried my best to do it, but in reality I had to consider the funds, equipment, and so on, on the one hand, it is impossible for us to build a unit for Weibo separately. After all, our game servers do not have this offer. On the other hand, I think this design means that when the server goes down every day, there is nothing to say to the players. The key is that the players are not satisfied with this service. In the end, the bamboo makes water empty. I don't even know why I am doing this. I am confused about it.

After about three months of design, the basic module is ready:

A CacheServer is used to deal with MySql databases. It encapsulates the underlying layer of MySql communication. The user's speech information can be cached in full cache (accelerated information extraction, because it is impossible to count on every information to go To the Select statement ).

A ControllerServer is responsible for communicating with CacheServer. It is mainly responsible for serving as a service buffer zone. In order to ensure that even if there is a large amount of data access demand, the server cannot be suspended, which makes the server unable to withstand problems, I block all requests at this layer. When the server is busy, I will put the requests down and extract data. All these requests are sent by N agents.

Scalable Agent: each game server (sometimes called a "line", is the concept of selecting a server for a game) is an Agent, the Weibo operation on the game client will be sent to the Agent on the server where the game client is located. The Agent first caches these commands, and then according to the configuration, it can know the maximum number of requests that the Agent can load (this request, in fact, it needs to be dynamically adjusted based on experience. I made it configurable and convenient for debugging and use .) The Agent sends a command to the Controller when it is idle.

I tried my best to keep it simple (code and architecture) and gradually realized the meaning of asynchronous, queue, hot and cold mechanisms, and cache. At the same time, we also recommend a widely-spread article about Weibo design. There are many articles on the Internet, which are the experiences of Sina Weibo architects. At first glance, this article does not help the details, but when I write this system in half, I will look at it and learn a lot of things to pay attention to during the architecture. At the same time, it also proves that, if someone else doesn't say yes in an article, you have to stick to it after reading it. It is helpful to understand it when you actually use it. So many people now read books from various great ox books, but they didn't actually use them, so the effect is very low.

Next, let's take a look at the cache. It has a capacity limit, but we want to store as much information as possible in the cache, because I hope that users can obtain their own attention and information as quickly as possible, but it is impossible to put all the information on the cache so that SQL database can be used for soy sauce, so here we need to use the data exchange. Don't talk about trick here. My idea is: the cache content is sorted by time, and the old content is replaced by the new one, but the time sequence is not the time when the user sends a new microblog, but the data extracted from MySql, the new data obtained by each operation is placed in a stack-like structure. This principle is to reduce the number of MySql queries. Of course, in extreme cases, the information that each user pays attention to is extremely different, the number of users is too large, so I can't hold this design.

It's so cold that I can't type it, so I have time to share it...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.