一、遇见问题
Batch_D_Account批量在生产机器上运行缓慢,平均运行时间长达五个小时之久,然后再重提时双击执行批量运行时间仅用三四分钟。
二、排查原因
经过多次测试,得到结果证明是通过windows计划任务启动程序慢于双击手动启动程序。查看两次程序进程的优先级不同,计划任务启动程序是低于正常(B)优先级,而双击启动是正常(N)优先级。
最终得出结论:windows计划任务启动程序优先级低导致程序运行慢。
三、解决办法
改变windows计划任务配置,设置优先级为高。具体步骤如下:
1.打开任务计划程序库运行Batch_D_Account批量,在任务管理器中查看进程优先级
2.导出Batch_D_Account任务
3.修改Batch_D_Account任务配置文件进程优先级为0
4.删除Batch_D_Account任务,如图:
5.导入修改好的Batch_D_Account任务配置文件,如图:
6.再次运行计划任务,查看Batch_D_Account.exe进程优先级为实时最高
7.完成,程序运行快了许多。
附件:进程优先级说明
1.进程级别:0 是最高优先级为实时
2.进程级别:10 是最底优先级
3.进程级别:7 是默认优先级
4.进程级别:7&8 是后台任务
5.进程级别:4&5&6 是交互任务
集体看:https://msdn.microsoft.com/zh-cn/library/windows/desktop/aa383512(v=vs.85).aspx
后记:如果错误,请帮忙校正,谢谢!
<?xml version="1.0" encoding="UTF-16"?> <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2015-07-30T15:44:53.0156462</Date> <Author>T1HHAPWEBI01\admin_batch</Author> <Description>商户月流水下载</Description> </RegistrationInfo> <Triggers> <CalendarTrigger> <StartBoundary>2015-07-30T08:10:00</StartBoundary> <Enabled>true</Enabled> <ScheduleByDay> <DaysInterval>1</DaysInterval> </ScheduleByDay> </CalendarTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId>T1HHAPWEBI01\admin_batch</UserId> <LogonType>Password</LogonType> <RunLevel>HighestAvailable</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> <AllowHardTerminate>true</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <IdleSettings> <StopOnIdleEnd>true</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> <AllowStartOnDemand>true</AllowStartOnDemand> <Enabled>true</Enabled> <Hidden>false</Hidden> <RunOnlyIfIdle>false</RunOnlyIfIdle> <WakeToRun>false</WakeToRun> <ExecutionTimeLimit>P3D</ExecutionTimeLimit> <Priority>0</Priority> <!-- 这里设置优先级--> </Settings> <Actions Context="Author"> <Exec> <Command>D:\Batch_file\Batch_D_Account\Batch_D_Account.exe</Command> </Exec> </Actions> </Task>