Table of Contents
流程
分库
更复杂的搜索
Home Database Mysql Tutorial 聊聊大数据环境下的数据库架构

聊聊大数据环境下的数据库架构

Jun 07, 2016 pm 04:24 PM
sub-table increase fast data database Architecture environment along with

随着数据的快速增长,分表,分库,memcache,redis,mongodb,hadoop,bigtable等,各种解决方案呼之欲出。经过测试,在MySQL中,无论如何加索引,数据超过百w时,查询起来耗时很明显。 因此mysql分表分库+memcache+redis也不失是一个完美解决方案。 由于redis不

随着数据的快速增长,分表,分库,memcache,redis,mongodb,hadoop,bigtable等,各种解决方案呼之欲出。经过测试,在MySQL中,无论如何加索引,数据超过百w时,查询起来耗时很明显。

因此mysql分表分库+memcache+redis也不失是一个完美解决方案。

由于redis不支持复杂查询,redis的读取性能还是赶不上mem这些劣势,因此才需要一些搭挡。

流程

从CRUD看底层架构。

1. 插入数据

一般情况下,对用户是没有必要分表的,用户的文章或者微博才分表,毕竟用户表和微博表是无法比拟,不一个等级的。

插入时,任何表,mysql只存储索引字段,其它数据存储在redis上。文章表可按一定规则进行静态分表,比如按用户id分100张表,每个用户发的文章都会路由到同一张表中。

数据总数需要一个单独的字段存储在redis中,每个用户都有一个key进行存储文章总数。有时总数数据会与实际总条数有所不同,因此需要定期执行mysql count进行更新redis中的总数。

下面是分表路由,把uid对100取余:

protected function getTableName($name, $id=null) {
   $tableName = self::SYS_DB_PREFIX . $name;
   if (is_numeric($id) && $id > 0)
       return $tableName . '_' . ($id % $this->tableNum);
} 
Copy after login

2. 查询数据

每第一次数据查询时,根据MySQL中的索引从redis查询,需要将查询结果存储在memcache中,下次查询直接从memcache获取。查询某人文章时,直接从一张表中进行limit查询。

关于动态页面查询,比如登录后的豆瓣首页,会有一些动态好友的更新信息。这些信息是存储在一张临时表中的,只保存10天的更新。

3. 删除数据

整个系统无任何实际操作,只进行字段状态修改。

4. 修改数据

修改数据时,需要更新对应的memcache。

分库

当系统应用更加复杂时,一台数据库服务器的压力是很大的,可根据系统的业务流进行分库,比如文章一个独立库,评论一个独立库等。

更复杂的搜索

比如招聘网站中的,按地点,按行业,按规模等更多条件查询时,就需要一定的搜索系统来完成,这里不做更多搜索细节讨论。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. May 07, 2024 pm 05:00 PM

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

Single card running Llama 70B is faster than dual card, Microsoft forced FP6 into A100 | Open source Single card running Llama 70B is faster than dual card, Microsoft forced FP6 into A100 | Open source Apr 29, 2024 pm 04:55 PM

FP8 and lower floating point quantification precision are no longer the "patent" of H100! Lao Huang wanted everyone to use INT8/INT4, and the Microsoft DeepSpeed ​​team started running FP6 on A100 without official support from NVIDIA. Test results show that the new method TC-FPx's FP6 quantization on A100 is close to or occasionally faster than INT4, and has higher accuracy than the latter. On top of this, there is also end-to-end large model support, which has been open sourced and integrated into deep learning inference frameworks such as DeepSpeed. This result also has an immediate effect on accelerating large models - under this framework, using a single card to run Llama, the throughput is 2.65 times higher than that of dual cards. one

What is the architecture and working principle of Spring Data JPA? What is the architecture and working principle of Spring Data JPA? Apr 17, 2024 pm 02:48 PM

SpringDataJPA is based on the JPA architecture and interacts with the database through mapping, ORM and transaction management. Its repository provides CRUD operations, and derived queries simplify database access. Additionally, it uses lazy loading to only retrieve data when necessary, thus improving performance.

2024 QS ranking released! Computer science MIT dominates the list, Tsinghua University is 11th, Peking University is 15th 2024 QS ranking released! Computer science MIT dominates the list, Tsinghua University is 11th, Peking University is 15th Apr 18, 2024 pm 09:04 PM

The 2024QS World University Rankings by Subject is here! Overall, there is little change from 2023. According to the official website information, the 2024QS World University Rankings by Subject covers 55 subdivisions and 5 major academic fields. A total of 1,559 universities participated in the ranking, 64 of which are new faces this year (that is, they will not appear in the 2023 ranking). Among these 64 colleges and universities, 14 are truly appearing for the first time. Among them is the University of Chinese Academy of Sciences. According to the refined subjects, Music is a new subject introduced this year. In addition, the data science and artificial intelligence rankings have been expanded, with 51 new universities added to the rankings. The top five in the overall list are: Massachusetts Institute of Technology, University of Cambridge, University of Oxford, and Harvard University

How steep is the learning curve of golang framework architecture? How steep is the learning curve of golang framework architecture? Jun 05, 2024 pm 06:59 PM

The learning curve of the Go framework architecture depends on familiarity with the Go language and back-end development and the complexity of the chosen framework: a good understanding of the basics of the Go language. It helps to have backend development experience. Frameworks that differ in complexity lead to differences in learning curves.

See all articles