views:

212

answers:

2

We have a task based multithreaded engine set up where a scheduler passes the task to the threads lock-free queue. The engine is in C++ with DirectX for the rendering and we are using boost::thread for creating the threads. When in windowed mode, it randomly slows down for a second or so and then speeds back up. It seems that it's something that Vista seems to be causing, but we can't figure out how to solve it properly.

One thing that we tried that seemed to help with the random slowdowns was making the thread sleep for a millisecond after each task has been processed, but it causes other problems and isn't really a great solution.

A: 

have you tried running the same code under XP and Windows 7?

I have some multithreaded code that renders to offscreen compatible bitmaps. Each thread renders to its own compatible bitmap. However for some odd reason this drawing takes AGES on vista. I lose over 50% of my processing time to the GDI rendering. Under Win 7 and XP I have no such problems. Interestingly I came across this article which implies that multithreaded GDI rendering under Vista is hopelessly broken. At some point I will try and come up with a method in which all rendering is done by my main thread instead of from ancillary threads to test out if Vista performance improves. This would be a huge nightmare of a thing to code though and my primary market uses XP so i'm not al; that fussed at the moment ...

Goz
I haven't tested it under XP yet, but it does do the same thing under Windows 7. Since the slowdown is happening randomly, with the same things happening each frame, I really don't see why the slowdown would be happening. Actually it's less like a slowdown and more like something blocks the thread for some time. The rendering starts stuttering and the framerate goes down from around 370 to 200, and then climbs back up to normal.
i reckon getting a profile is your only way forward then ...
Goz
VTune 30 day demo is probably the best thing but it'll take you most of those 30 days to interpret the data you get back ...
Goz
+1  A: 

The first thing I would recommend doing is understanding what's causing the slowdown by profiling.

Throwing in random sleeps is rarely a good idea (speaking from experience here, yes I've done this and yes I've fixed this later) and neither is speculating on sources of performance problems particularly in a multi-threaded environment.

Visual Studio 2010 beta1 has a great profiler that is perfect for understanding what's causing the slowdowns if it's within your application, Hazim Shafi's blog walks through how to use it.

You can also look at the xperf tool which is available in the windows performance toolkit (you have to use the platform sdk installer, but you only need to install that node so it's actually pretty fast).

Rick
I don't like the sleeps being in there and am looking for a way to get rid of them and fix the problem properly. I will look into VS 2010, I've been looking for a good profiler that does threading, but I could only find the Intel profiler which costs too much.The reason why I'm speculating that it's something with Vista is that the slowdown happens even when there is only one task for the rendering, and the second core is left idling. In the rendering task, things are set up to where it's just passing data to DirectX, no allocations, or blocking or anything that might cause slowdowns.
vs 2010 is in beta right now, so it's effectively free. the windows performance toolkit (xperf) is also free, both should show the source of the slowdown, but I think that it will be easier to find in the vs 2010 profiler. I think amd also has a thread profiler which is free.
Rick