In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to optimize cloud MongoDB to improve the service performance of LBS ten times? in view of this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
With the popularity of domestic service sharing, sharing bicycles, umbrellas, sharing portable battery and other services are springing up, the subsequent LBS service location has become a challenge for back-end services. MongoDB has friendly support for LBS query, and it is also the preferred database for major LBS service providers. During the operation, Tencent Cloud MongoDB team found that native MongoDB has a big performance bottleneck in LBS service scenarios. After professional positioning analysis and optimization by Tencent Cloud team, Cloud MongoDB has improved the overall performance of LBS services by more than 10 times.
The excellent comprehensive performance provided by Tencent Cloud MongoDB provides a strong guarantee for major domestic LBS service providers, such as mobike.
LBS service characteristics
Taking the shared bicycle service as an example, LBS service has two characteristics, namely, time periodicity and uneven coordinate distribution.
I. the periodicity of time
There was a significant difference in QPS between peak and trough periods, and the time points of peak and trough periods were relatively fixed.
two。 Uneven distribution of coordinates
Commuters who take the subway, if they pay attention, they may find that during the morning rush hour, the subway is surrounded by shared bikes, while during the off-work period, the number of shared bikes around the subway is very small. As shown in the following figure, more than 99% of the coordinates are concentrated near latitude and longitude (121 ~ 31.44). In addition, some special events will also cause uneven distribution of points, such as Shenzhen Bay Park in the special family holiday influx of a large number of customers, at the same time, this area will also put a large number of bikes. The number of bikes in some areas is very concentrated, while others are very sparse.
The LBS Service principle of MongoDB
MongoDB uses 2d_index or 2d_sphere_index to create a geolocation index (geoIndex). There is little difference between the two. Let's take 2d_index as an example.
I. creation and use of 2D index
Db.coll.createIndex ({"lag": "2d"}, {"bits": int}) creates a 2d index through the above command, and the precision of the index is specified by bits. The larger the bits, the higher the precision of the index. The inserted overhead brought by a larger bits can be ignored db.runCommand ({geoNear: tableName,maxDistance: 0.0001567855942887398reparentdistanceMultiplier: 6378137.0, num: 30 near: [113.8679388183982,22.58905429302385], spherical: true | false})
Use the above command to query an index, where spherical:true | false indicates how to understand the created 2d index, false means to understand the index as a flat 2d index, and true means to understand the index as a spherical longitude and latitude index. This is interesting because a 2d index can express two meanings, and the different meanings are understood at query time, not when the index is created.
II. The theory of 2D index MongoDB uses GeoHash's technology to build a 2d index (see wiki geohash text chain https://en.wikipedia.org/wiki/Geohash). MongoDB uses plane quadtree partition to generate GeoHashId. Each record has a GeoHashId, which is stored in Btree through the index mapping of GeoHashId- > RecordId.
Obviously, the accuracy of one 2bits can divide the plane into four grid, and the accuracy of one 4bits can divide the plane into 16 grid. The default precision of the 2d index is 26 in length and width. The index divides the earth into (2 ^ 26) (2 ^ 26) blocks, and the side length of each block is estimated as 2PI6371000/ (1).
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.