MySQL Cluster使用到目前为止遇到渴望得到答案的问题,也是直接影响使用的问题就是MySQL Cluster的写入效率问题和Cluster是否适合大数据存储、如何配置存储的问题。 在之前的测试中MySQL Cluster的写入效率一直不佳,这也是直接影响能否使用MySQL Cluster的
MySQL Cluster使用到目前为止遇到渴望得到答案的问题,也是直接影响使用的问题就是MySQL Cluster的写入效率问题和Cluster是否适合大数据存储、如何配置存储的问题。
在之前的测试中MySQL Cluster的写入效率一直不佳,这也是直接影响能否使用MySQL Cluster的关键。现在我们来仔细测试一下。使用的环境略有变化。
Data节点的内存扩展为4G。
集群配置如下:
[ndbd default] # Options affecting ndbd processes on all data nodes: NoOfReplicas=2 # Number of replicas DataMemory=2000M # How much memory to allocate for data storage IndexMemory=300M # How much memory to allocate for index storage # For DataMemory and IndexMemory, we have used the # default values. Since the "world" database takes up # only about 500KB, this should be more than enough for # this example Cluster setup. MaxNoOfConcurrentOperations=1200000 MaxNoOfLocalOperations=1320000
测试代码如下:
/** * 向数据库中插入数据 * * @param conn * @param totalRowCount * @param perRowCount * @param tableName * @author lihzh(OneCoder) * @throws SQLException * @date 2013 -1 -17 下午1:57:10 */ private void insertDataToTable(Connection conn, String tableName, long totalRowCount, long perRowCount, long startIndex) throws SQLException { conn.setAutoCommit( false); String sql = "insert into " + tableName + " VALUES(?,?,?)"; System. out.println( "Begin to prepare statement."); PreparedStatement statement = conn.prepareStatement(sql); long sum = 0L; for ( int j = 0; j <p> 分下列情景进行写入测试。</p> <p> 数据加载、写入在内存中时,在独立的新库、新表中一次写入100,1000,10000,50000条记录,分别记录其耗时情况。(5次平均)</p> <pre class="brush:php;toolbar:false"> 100:260ms 1000:1940ms 10000:17683ms(12000-17000) 50000: 93308、94730、90162、94849、162848
与普通单点MySQL写入效率进行对比(2G内存)
100:182ms 1000:1624ms 10000:14946ms 50000:84438ms
双线程并发写入测试
由于只有两个SQL节点,所以这里只采用双线程写入的方法进行测试。代码上采用了简单的硬编码
/** * 多线程并行写入测试 * * @author lihzh(OneCoder) * @blog http://www.coderli.com * @date 2013 -2 -27 下午3:39:56 */ private void parallelInsert() { final long start = System. currentTimeMillis(); Thread t1 = new Thread( new Runnable() { @Override public void run() { try { Connection conn = getConnection(DB_IPADDRESS, DB_PORT, DB_NAME, DB_USER, DB_PASSOWRD); MySQLClusterDataMachine dataMachine = new MySQLClusterDataMachine(); dataMachine.insertDataToTable(conn, TABLE_NAME_DATAHOUSE, 500, 100, 0); long end1 = System.currentTimeMillis(); System. out.println( "Thread 1 cost: " + (end1 - start)); } catch (SQLException e) { e.printStackTrace(); } } }); Thread t2 = new Thread( new Runnable() { @Override public void run() { try { Connection conn = getConnection(DB_IPADDRESS_TWO, DB_PORT, DB_NAME, DB_USER, DB_PASSOWRD); MySQLClusterDataMachine dataMachine = new MySQLClusterDataMachine(); dataMachine.insertDataToTable(conn, TABLE_NAME_DATAHOUSE, 500, 100, 500); long end2 = System.currentTimeMillis(); System. out.println( "Thread 2 cost: " + (end2 - start)); } catch (SQLException e) { e.printStackTrace(); } } }); t1.start(); t2.start(); }
测试结果:
(总条数/每次) | 线程1(总/平均- 各写一半数据) | 线程2 | 并行总耗时 | 单线程单点 |
1000/100 | 985/197 | 1005/201 | 1005/201 | 2264/226 |
10000/1000 | 9223/1836 | 9297/1850 | 9297/1850 | 19405/1940 |
100000/10000 | 121425/12136 | 122081/12201 | 121425/12136 |
148518/14851 |
从结果可以看出,在10000条以下批量写入的情况下,SQL节点的处理能力是集群的瓶颈,双线程双SQL写入相较单线程单节点效率可提升一倍。但是当批量写入数据达到一定数量级,这种效率的提升就不那么明显了,应该是集群中的其他位置也产生了瓶颈。
注:由于各自测试环境的差异,测试数据仅可做内部比较,不可外部横向对比。仅供参考。
写入测试,要做的还很多,不过暂时告一段落。大数据存储和查询测试,随后进行。
原文地址:MySQL Cluster写入效率测试, 感谢原作者分享。

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools