使用java比较两个大型数据集的有效方法是什么
我正在为以下需求创建一个基于java的实用程序-使用java比较两个大型数据集的有效方法是什么,java,performance,jdbc,compare,Java,Performance,Jdbc,Compare,我正在为以下需求创建一个基于java的实用程序- 使用SQL查询从旧数据库获取500k条记录 使用一个一次只能获取一条记录的Web服务从现代化的数据库中获取500k条记录 比较两个数据集 生成比较报告 我按照以下方法完成了该实用程序的开发- Connection con = establishLegacyDBConnection() // Using JDBC connect to database ResultSet resultset = executeLeagacyQuery(Conne
Connection con = establishLegacyDBConnection() // Using JDBC connect to database
ResultSet resultset = executeLeagacyQuery(Connection con, String query)
while(resultset.hasNext()) {
// Comparing one record at a time. For each resultset record compare data with webservice response
1. Read the record to map1.
2. GET the response from webservice based on a value in map1.
3. Capture the response and parse the Json, read required fields to map2 (Both maps have same set of keys).
4. for each key in map1, compare map1 value with map2 value.
5. If there is mismatches, write the key-value information to a flat file - "Non-Matching.txt"
6. If all key-values are matching, write a message to a flat file - "Matching.txt"
}
现在的问题是,这个程序需要几十个小时才能完成执行。是否有更好的方法来解决此问题并提高性能?我希望您也先将问题分开
试试看,祝你好运我也希望你先把问题分开
试试看,祝你好运看看你当前方法的伪代码,我突然意识到一次一个地向Web服务器发送请求可能是一个瓶颈。如果是这样,那么您可以尝试以下方法:
Connection con = establishLegacyDBConnection() // Using JDBC connect to database
ResultSet resultset = executeLeagacyQuery(Connection con, String query)
while(resultset.hasNext()) {
// Comparing one record at a time. For each resultset record compare data with webservice response
1. Read the record to map1.
2. Submit a task to a Executor service with a bounded work queue and a bounded thread pool.
Each task does this:
1. GET the response from webservice based on a value in map1.
2. Capture the response and parse the Json, read required fields to map2 (Both maps have same set of keys).
3. for each key in map1, compare map1 value with map2 value.
4. If there is mismatches, write the key-value information to a flat file - "Non-Matching.txt"
5. If all key-values are matching, write a message to a flat file - "Matching.txt"
换句话说,并行处理遗留查询中的记录
诀窍在于调整:
- 调整线程池大小,使应用程序处于关键忙状态,但不会让web服务器同时收到太多请求
- 调整工作队列大小,使工作线程不会耗尽工作,但队列不会使用太多内存
如果瓶颈在数据库端,也可以考虑并行化该边;e、 g.在遗留数据集的“切片”上并行运行多个查询。
查看您当前方法的伪代码,我突然想到,将请求一次发送一个到Web服务器可能是瓶颈。如果是这样,那么您可以尝试以下方法:Connection con = establishLegacyDBConnection() // Using JDBC connect to database
ResultSet resultset = executeLeagacyQuery(Connection con, String query)
while(resultset.hasNext()) {
// Comparing one record at a time. For each resultset record compare data with webservice response
1. Read the record to map1.
2. Submit a task to a Executor service with a bounded work queue and a bounded thread pool.
Each task does this:
1. GET the response from webservice based on a value in map1.
2. Capture the response and parse the Json, read required fields to map2 (Both maps have same set of keys).
3. for each key in map1, compare map1 value with map2 value.
4. If there is mismatches, write the key-value information to a flat file - "Non-Matching.txt"
5. If all key-values are matching, write a message to a flat file - "Matching.txt"
换句话说,并行处理遗留查询中的记录
诀窍在于调整:
- 调整线程池大小,使应用程序处于关键忙状态,但不会让web服务器同时收到太多请求
- 调整工作队列大小,使工作线程不会耗尽工作,但队列不会使用太多内存
如果瓶颈在数据库端,也可以考虑并行化该边;e、 g.在遗留数据集的“切片”上并行运行多个查询。
您可以直接在数据库上进行比较(不管是什么)。例如,可以从MySQL跨数据库调用SQL Server(或Oracle)。也许可以研究一下这种方法。由于许多原因,将大量结果集引入JVM是错误的。首先,它占用了大量内存。第二,Java不是真正的数据分析工具(但您的数据库是)。由于一些安全限制,我无法直接连接到现代化的数据库并对其执行SQL查询。查询此数据库的唯一方法是通过webservice。所以我不能直接比较两个数据库。我还考虑了将大量结果集加载到内存中的含义。因此,我使用setFetchSize(1000)将行集分块加载到内存中。我想这没什么帮助。再说一遍,我不知道你的比较是什么,但它需要将两个表具体化到内存中,然后按块加载可能不符合你的规范。你可以直接在数据库上进行比较(不管是什么)。例如,可以从MySQL跨数据库调用SQL Server(或Oracle)。也许可以研究一下这种方法。由于许多原因,将大量结果集引入JVM是错误的。首先,它占用了大量内存。第二,Java不是真正的数据分析工具(但您的数据库是)。由于一些安全限制,我无法直接连接到现代化的数据库并对其执行SQL查询。查询此数据库的唯一方法是通过webservice。所以我不能直接比较两个数据库。我还考虑了加载海量数据库的含义