【发布时间】:2017-09-11 14:47:28
【问题描述】:
我正在开发一段代码,用于将项目大量导入数据库。 Excel 文件中的总记录为 24103。由于大量验证,最初导入 700 行记录的总时间为 40 分钟。现在,在减少战略步骤后,所有记录的时间已减少到 24 分钟。现在有 4 个活动可以相互独立地并行执行。我尝试通过async.parallel 进程并行执行的那些活动。但是当我看到用于调试的控制台时,我才知道它仍然一次执行一条记录。只是不同之处在于正在插入的记录的改组。并且在所有执行之后,它所花费的时间与活动顺序执行之前所花费的时间相同。以并行方式执行(插入)的另一种可能的方法是什么。
我的步骤包括
flowController.on('START', function () {
// Uploading and storing the binary data as excel file
});
flowController.on('1', function () {
// Validation to check if file contain required sheet with name and all and convert the file into JSON format
});
flowController.on('2', function () {
// Replacing the keys from the JSON to match the required keys
});
flowController.on('3', function () {
// Massive validation of records & seperating the records as per the activity
});
// Activity 1
flowController.on('4', function () {
// Insert records of Activity 1
});
// Activity 2
flowController.on('5', function () {
// Insert records of Activity 2
});
// Activity 3
flowController.on('6', function () {
// Insert records of Activity 3
});
// Activity 3
flowController.on('END', function () {
// End
});
【问题讨论】:
-
如果这些是同步活动,异步并行将无济于事
-
也许你应该展示你的代码。如果运行 700 行需要 40 分钟,那么你就做错了。底线是你在问“我能做到吗?”没有真正向我们展示你在做什么。作为一般性问题过于宽泛。
-
@SuhailGupta 我没听懂你......
-
@NeilLunn 这可能是我的第一行陈述。此外,我提到我战略性地减少了验证步骤。我提到的时间包括验证和插入操作。为了您,我将更新问题以更好地理解上下文