Pages

Thursday, May 30, 2013

A huge pile of tmp files and CCleaner to the rescue

I've been working on a tool to measure the performance of print jobs and one little bug in it completely destroyed my day at work, but Luckily I had CCleaner to help me fix the problem. The concept of the tool is simple, but because I have to use multithreading it's gotten pretty complex, revision over revision.

The objective of the tool is simple. Whenever we make a substantial modification to the source of the renderer, we have to test for any degradation in performance. We have a bunch of XPS files and we simply use the AddJob method of the PrintQueue API to send the XPS data to the printer. This was a simple tool which was developed in the ancient days. So we add job after job to the printer and measure how long it takes to finish each print job. There was a separate tool that automatically dumped the start time and the finish time of the print job. (Did you think we measured it using a stopwatch?) Obviously we have to do this few time for each XPS file and take the average. It is such time waste.
 
The tool I wrote does this automatically. I just have to install the printer driver, load the data and bang. So easy. A lot of time saving.
 
There were some issues though. One of them was, sometimes the PrintFilterPipelineService, which is the process the print job is managed by, since Vista days, sometimes skips the print the job without doing anything if a new job is sent soon after the previous one finished.  I've noticed this on my Athlon X2 4200+ rig, but not on the Core i7 2600 rig or the common test rig with Core i5 750. Anyways, the solution was to kill that process after every print job.
 
That worked fine until I had to measure the performance of a large amount of XPS files last week. I could actually finish the performance test alright, but the next day when I booted into Windows in the morning, the desktop didn't respond to my inputs for about 10 minutes!!! The problem didn't go away even after a multiple reboots. When I checked the Resource Monitor, I noticed that the Print Spooler service was doing a lot of I/O. When I stopped the Print Spooler service, the stalling stopped. But I need the Print Spooler service running. After a little bit of snooping around, I found the problem.
 
There were over 250,000 tmp files in the folder C:\Windows\System32\Spool\PRINTERS. Those tmp files should not be left behind. They should automatically be cleaned out when the print job finishes. I guess it is done by the PrintFilterPipelineService. Because I kill it as soon as the print job finishes, it does not get the chance to clean up those tmp files. They had just kept adding up.
 
When I tried to delete those files, I couldn't even go into that folder from Windows Explorer. Nor command prompt. I simply tried to delete using this trick, but it was no good.
 
Luckily, I had CCleaner. You can add custom folder locations which needs to cleaned up when you run it. You can add them from the following screen.
 
image
 
image
 
After that, I could at least delete the files. It took a long time - about 3hrs - to get rid of them all but at least it worked. Once those tmp files were out of the way, the performance of the PC was back to where it was. I obviously made some modifications to the tool and I have to make it more "intelligent". But all those fun stuff has to wait until I get some free time.
 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...