Welcome toTencent Cloud + community, get more Tencent mass technology practice dry goods oh ~
This article was published in cloud + Community column by Tencent Cloud database TencentDB
Today I share the theme content is about two parts, the most important is small games and small programs, the first part is to share with you our experience in the current network operation service small games and popular small games accumulated. We have made some changes in the operation and maintenance of the live network to help the small game to run stably. In the second part, we launched a new solution suitable for small white developers and start-up companies. They can use Tencent cloud resources and enjoy various services of Tencent Cloud while developing small programs in wechat.
Talk about the first part of the content, just zou Peng finally said a paragraph of time, there has been a picture, that picture is the ranking of all kinds of databases, you may not notice that the ranking of MongoDB is actually the fifth, say again why MongoDB is suitable for game development scenarios. We know the game development in one of the most main characteristic is to demand changes very fast, because of the different stages in the game will add some new elements stick users, such as props, props in the online game at different stages and different, the traditional relational database unavoidable DDL operations carried out on the table structure changed, there may be some developers said don’t need, All I did was pack all the fields into a single field into a library table. Using MongoDB without changing the table structure is Nice for developers. In addition, most games add social elements to keep users engaged and engaged. We provide the geolocation index and the accompanying API, no need to operate in the business layer, the database layer is already supported natively. Massive data support, we provide the function of sharding, in fact, at the beginning of the data, at the beginning of the business online, do not know what kind of magnitude in the future. If relational database is used, it is unavoidable to divide database, divide table and expand capacity later. MongoDB provides sharded cluster, which can carry out horizontal expansion without affecting business, which is a very good solution for operation and maintenance.
Operation analysis, now is the era of big data, every business will support the operation strategy according to the results of data analysis, we are native support MapReduce, developers can directly use. It’s also important to note that if you’re developing small programs, you’re writing in JS, there’s a javascript stack of MEAN and MERN, and MongoDB and Nodejs that have grown up with each other. In short, MongoDB is particularly well suited to game development scenarios.
I would like to ask you now have not used our Tencent cloud MongoDB? Or is it MongoDB? You can also build your own. What data do you store with MongoDB? (currently collecting user behavior logs) is it self-built? (Yes, originally wanted to use the cloud, but later found that it would be cheaper to build.) One master and two masters or one master and one slave? How big is the instance? (now tens of gigabytes of data) how big is the CVM you bought? (500 g space, we prior to use, it is not too clear, a direction is a temptation, in before I use is ali, tencent is begin to contact this year) I probably understand, so I think today can stand here to share, to meet so many users, for me personally is a very happy thing, At least I know how you’re using it now and if it’s working, so I don’t have to visit them all.
Small game call stack, many developers are very clear, I just need to take a simple, generally in the front of the load balancing, and then through the virtual machine to build a server, behind the database.
I mentioned to you just now that we have served many popular small games on the live network. One of the main purposes is to ensure the stable operation of customers’ games. In the process of serving them, we have accumulated some operation and maintenance experience and adjusted some connection parameters to help customers maximize the instance value.
The connection model of MongoDB is divided into two parts. The first part is Mongos connection to the client, and the second part is Mongos connection to the back end. The first part is connected in a very old way called one-thread-per-connection, and each connection is assigned a Thread. 1MB memory per thread stack and 1GB memory for 1000 connections, so MongoDB is very sensitive to connections. The model of back-end connection is that each Mongos will bind a Worker pool. If you have three shards, and each shard has one master and two slaves, that is 9 Mongods, each Worker will have 9 connections.
If there is a parameter, the parameter design is unreasonable, the business volume is higher, the connection pool of threads is not enough to use, will be to switch from the frequent thread scheduling and, because of the switch and thread scheduling overhead is relatively large, so the operations staff is more concerned about minConnection this parameter, This parameter is proposed separately and can be directly modified by operation and maintenance personnel. There is a formula for setting this parameter, and the formula is that you need to set this parameter according to, for example, the current TPS is 1000, each connection requires processing 10 milliseconds, 2 fragments,minConnection=1000/2/(1000/10). The second parameter is refreshRequirement, which means that there is an estimated connection peak value for each service. Therefore, the value of refreshRequirement should be set over 5 minutes. The above is our optimization of MongoDB connection model.
The second one is the slow query problem that we encounter when serving many small games on the current network. Many users better understand mongo, because it is a main from two, would be to reduce the pressure of the Lord, is set to hit from a read request, from can synchronize data, can also receive read requests, the main do receive written request, this is the ideal solution, but we found the solution in the process of service users may cause problems, because from version 3.2, The default engine is WT. WT engine has an operation is in when synchronous data will add a global lock, the lock can lock all read request, will get more slow query could thus, based on this problem, our side is to get a patent, the patent is a scheme based on snapshot of reading, is when you are from reading, at this time let you read the snapshot, After data synchronization is complete, all read requests are normal and the snapshot is cleared. Another solution, shown on the far left, is that we provide a read-only instance, which is mounted on the master instance, which receives read/write requests, and the other business modules just call all connection requests read-only. The advantages of these two solutions are not obvious in general, but when your instance Primary is under a lot of write pressure, they are. The blue part is the source Mongo, and the red part is a performance based on the way we read snapshot. The X-axis is the write size, and the Y-axis is the latency of the read request from the library. We found that the maximum read latency in the source Mongo can reach about 85 milliseconds. With our solution, it’s around 10 milliseconds, which is really fast. So that’s our second optimization.
When the business goes online at the beginning, it is not known how much the later magnitude can reach. Assuming that developers apply for relatively large instances at the beginning, it will be challenged by operation and maintenance. This problem can be avoided by using a sharded cluster. You start small, you buy a small shard, and then when you get a lot of business, you expand the shard horizontally. You only need to specify the Key of the fragment to allocate data to different slices for automatic balancing without service awareness.
Library table back to file, in the process of game operation and maintenance of a more painful thing to need to file back. It is really painful. Sometimes I feel that some users are very anxious in the process of reloading. Once they refile, they should refile to the previous time period because something serious has happened. Because there are bugs in the program, or when the game is launched, a Leader shakes hands and gives out a lot of props, which may cause a lot of RMB losses. At this time, it is necessary to file back. However, it is only a certain library table to file back, and the whole instance does not need to file back. In this case, we support library table file back, which is a very nice function for operation and maintenance personnel.
My second part is a solution for mini-games and mini-programs. Small program development and little game development, especially the game will encounter a problem, the use of local cache 30 to 40 m completely was not enough, how to put the small program can assign to the cloud, we provide a solution, don’t need to buy tencent CVM, database, function, only need to click on the small application development IDE console button, developers only need to pay attention to the implementation of business logic, Back-end server operation and maintenance knowledge is no longer necessary to understand. The characteristics of small games and small programs are short and fast, fast online, iterative fast method, occupy the market, through some props and advertising quickly realized, the life cycle is not long.
Our solution has database management, file management, function management in the service layer, and some log and trigger services will be added. The underlying services include Tencent cloud MongoDB and cloud function. That is to say, just now we in the service of other games in the operation and maintenance experience of the accumulated will be applied to this solution, so we can rest assured to use.
There will be multiple environments in the development process, such as development environment, test environment and production environment. After opening this service on the cloud, we will include multiple environments by default, and the environments are isolated from each other.
This solution is especially suitable for individual developers, start-up teams, and mature teams that need to work on some projects right away. The following is our console, with three functions, you can create collections, we added import and export functions, you can import data from other places into it so that your small program can run directly. The second is the index. We have prioritized the index function. By default, the _ID field is indexed, and users can add their own single-column index and composite index. In addition, the permission management here is very elaborate.
My share for today goes something like this. More database cutting-edge technology can pay attention to our public number: Tencent cloud database CDB
Q&A:
Q: Hello, teacher, you just talked about monitoring data, I would like to ask whether the small program can let users see logs and monitoring data? Do you provide an alarm mechanism?
A: I think you’ve thought about this A lot. It is. Monitoring and logging are important. Logging will be included in the solution soon, using ES. Monitoring metrics are now the same as MongoDB public cloud data. Alarms We have made policies to automatically set pre-values for the alarm system of key indicators. Automatic alarms and user-defined alarms are not provided in the short term.
Q: Hello, teacher, I have worked hard this afternoon. I used to know little about MongoDB. I heard that MongoDB has a security event, which should be within a year, but the specific time is not clear. I want to know, for example, about the security of Mongo on the cloud, how do you do?
A: Security has two points. The first point is network. We will add security group in front of it, so that the source IP addresses can be filtered at the first layer. Second, we added a VPC network, so that only CVMS with the same network class as their own virtual machines can access our Mongo, so as to achieve network isolation. Second, we have data encryption, we are now doing storage encryption, the encryption function is the user can choose when buying, so using our Tencent cloud MongoDB security is completely at ease, but you may not be so self-built.
Q: The VBC you just said, if it is built by itself, our network is independent.
A: If you build it yourself, VBC can do it, but data layer encryption cannot.
Machine learning in action! Quick introduction to online advertising business and CTR knowledge
This article has been authorized by the author to Tencent Cloud + community, more original text pleaseClick on the
Search concern public number “cloud plus community”, the first time to obtain technical dry goods, after concern reply 1024 send you a technical course gift package!
Massive technical practice experience, all in the cloud plus community!