mgduoduo opened a new issue #7256:
URL: https://github.com/apache/dolphinscheduler/issues/7256


   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar feature requirement.
   
   
   ### Description
   
   The action ```/projects/{projectCode}/task-instances``` is very slow,  
   
![image](https://user-images.githubusercontent.com/13417113/145129958-3bf0e76f-c611-4c12-a312-0d9123b3e1a5.png)
   
   Total count of table ```t_ds_task_instance``` is only 100, 000 +.
   
   Below is the query sql for the action.
   ``` sql
   select
           // ...
           process.name as process_instance_name
           from t_ds_task_instance instance
           left join t_ds_task_definition_log define on 
define.code=instance.task_code and 
define.version=instance.task_definition_version
           left join t_ds_process_instance process on 
process.id=instance.process_instance_id
           where define.project_code = #{projectCode}
          // ...
   ```
   
   I have 2 sugguestions for the performance optimization.
   1. create a index for table ```t_ds_task_definition_log``` on column 
```code```,
   the query performance is improved obvisouly.
   
![image](https://user-images.githubusercontent.com/13417113/145131412-932b3579-9573-4f16-b4ae-e4a7eb1f4fbe.png)
   
   2. the logic could be optimized in 
org.apache.dolphinscheduler.api.service.impl.TaskInstanceServiceImpl#queryTaskListPaging.
   ``` java
   for (TaskInstance taskInstance : taskInstanceList) {
               
taskInstance.setDuration(DateUtils.format2Duration(taskInstance.getStartTime(), 
taskInstance.getEndTime()));
               // TODO it could be optimized here.
               User executor = 
usersService.queryUser(taskInstance.getExecutorId());
               if (null != executor) {
                   taskInstance.setExecutorName(executor.getUserName());
               }
           }
   ```
   such as assemble an user map ```Map<Long, User> userMap``` outside of the 
loop.
   
   
   ### Use case
   
   improve the query performance.
   
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to