Table of Contents
回复内容:
Home Backend Development PHP Tutorial 约 1亿条记录, 每条1k左右,key =>value形式,用于前台查询,选择什么作为存储方案比较合适呢,要求效率比较高并且相对稳定可靠?

约 1亿条记录, 每条1k左右,key =>value形式,用于前台查询,选择什么作为存储方案比较合适呢,要求效率比较高并且相对稳定可靠?

Jun 17, 2016 am 08:32 AM
mysql

每天需要从文件导入一次,目前想到使用mysql分表存储,不知道有没有更好的办法。

回复内容:

对于这个小问题, 如果 key 比较小, 可以将所有 key-pos 放内存, pos 为文件中 value 的偏移, 每次访问只需要一次磁盘seek.

用 protocol-buf 或 thrift 架成网络服务, 还可以加一层proxy, 按 key hash 分发到不同的服务器来减小压力.

嗯, 好像这些, beansdb 都已经做好了. 数据之间没有强关联,这种情况下用mongo+redis是比较合适的,热点数据保留在redis里,其他数据md5分散到若干台mongodb. 然后请求分散到不同的mongodb上.
扩展也方便 1.总元数据量是100G不到,加上主键索引的话,预计100G-120G

2.每天需要从文件导入一次,目前想到使用mysql分表存储,不知道有没有更好的办法 ?这个不太清楚,是当下已经有1亿条记录,还是每天累加在一起之后,可能为1亿条记录

这个非常关键,若是每天累计在一起是1亿条记录,且是按PK查询查询的话,没有必要分表



3.非常关键的一点,只有查询 还是可能也提供其他的操作,比如UPDATE,INSERT,一定要确认清楚

4.查询的话是按PK单条的方式,还是大批量的读出,关键点是否需要GROUP BY 统计,ORDER BY 分页


5.主键是否简单比如1个或2个整型字段的模式

6.采用MySQL的话,若是非常简单的查询,且按PK,可以考虑采用Handlersocket的模式,对于复杂的建议走SQL协议...


推荐handlersocket的技术文章资料:
HandlerSocket的原理等系列篇章
mysqlops.com/2011/10/19

1. mongodb+redis
更酷,且对于你的场景来说,没有风险(即使丢失1天数据,也可以重新导入),成熟可靠.
mongodb存储数据(须使用主从or replication set),redis做cache.
2. mysql+memcached.
毫无疑问可以实现你的需求. 倒入之后只读的?用 java 随便写一个就可以了吧。index 放在内存,数据放在硬盘。如果访问有冗余,加个 cache 就好了。 使用Redis+Mysql吧,Mysql作磁带,Redis做前台的查询,比较合适。稳定,快速。 推荐用redis,它把k-v数据缓存在内存里面,性能很高,技术成熟稳定好,支持主从同步 thuir.org/thuirdb/
刚在微博上看到的,非常符合你的需求。

当然,不推荐使用不成熟的技术。 mark mysql用来存数据,redis用来查询,纯内存操作,速度绝对快!

缺点是硬件投入较大,1亿条数据全得存到redis服务器的内存里,redis里用不上的功能,全部不用。
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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 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)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

The difference between oracle database and mysql The difference between oracle database and mysql May 10, 2024 am 01:54 AM

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

See all articles