Question on Wine CPU usage

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
cnbiz850
Level 3
Level 3
Posts: 65
Joined: Sun Nov 08, 2009 9:54 pm

Question on Wine CPU usage

Post by cnbiz850 »

I made some simple comparisons about CPU usages between running Wine and running XP on a VirtualBox. In both cases, I ran exactly the same 2 applications with about the same configuration. The Wine I use is 1.3.26. The XP is XP Home with SP2 but trimmed down to nearly its bare-bones (having only the possibly minimum number of services running). The computer is a Dell Studio laptop with "Intel Core 2 Duo CPU P8700 2.53GHz" and 4GB of RAM running Ubuntu 10.10 64bits. The virtual machine for XP is configured to use 1 CPU and 512MB of RAM. Separately, I used "top" to measure the CPU usages. Results are as follows:

These numbers are from running Wine:

Code: Select all

  PID USER          PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
13770 cnbiz850      20   0 2665m 110m  15m S   16  2.8   1:12.70 mytrader2009.ex    
14073 cnbiz850      20   0 2632m  60m  11m S   14  1.5   0:45.51 TradeBlazer.exe    
14230 cnbiz850      20   0  9036 6080  708 S   10  0.2   0:29.95 wineserver                          
13773 cnbiz850      20   0  7084 4356  692 S    6  0.1   0:35.47 wineserver         
14258 cnbiz850      20   0 2603m  31m  14m S    2  0.8   0:06.99 tbdatacenter.ex    
The following numbers are from running XP:

Code: Select all

  PID USER          PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
20603 cnbiz850      20   0 1268m 649m 599m S   23 16.5   3:56.50 VirtualBox         
Notice the difference in CPU usage is pretty significant. In the Wine case, total is about 48%, and in XP' case, it is 23%.

I have been under the impression throughout the years that Wine uses much less resources than using a virtual machine, and also feel that I understand that in theory. But can anyone please explain about the above results? Is there anything wrong, or am I missing something?
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Re: Question on Wine CPU usage

Post by doh123 »

First.. why is there 2 wineservers running? something looks like it might not be working correctly...

When its running Idle... VirutalBox has some ways to try to cut down CPU usage since its handling everything and not the main OS. When you start running a program hard in VirtualBox and in Wine it won't be much different... VirtualBox is also going to be using your virtualization support on your CPU.

Try getting top going where you can see it and have VB in a window, making it the active app and start using it and see where the CPU numbers go.

Also look at your memory usage there and see which one is eating up all the ram.
cnbiz850
Level 3
Level 3
Posts: 65
Joined: Sun Nov 08, 2009 9:54 pm

Post by cnbiz850 »

Thank you, doh123 for the reply.

I guess the reason that there are 2 wineservers is that I had the 2 applications installed under 2 different WINEPREFIX'es and run them with "WINEPREFIX=..." before the wine command. (does wineserver only appear once if both are within the same WINEPREFIX?)

Let me further clarify how I ran the apps and did "top". In the Wine case, I ran TradeBlazer on Desktop 2 and mytrader2009 on Desktop 3, then I did "top" on Desktop 1. Then I quit out both wine'd apps. Starting anew on Desktop 4, I started the XP on VirtualBox and then started the 2 apps in XP. Then again I did "top" on Desktop 1. That generated the results I posted above.

Now I just tried your suggestion about running top on the same desktop as the apps. Let's see the results:

In the Wine case, I ran the 2 apps on Desktops 2 & 3 (running them both on the same desktop is not quite convenient as the TradeBlazer window always tries to pop to the top) and I did "top" on Desktop 3 (where mytrader2009 is). The numbers:

Code: Select all

  PID USER      	PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                   
29728 cnbiz850      20   0 2666m 112m  15m S   35  2.9   1:23.48 mytrader2009.ex           
 1415 root      	20   0  293m  68m  43m S   22  1.7 100:20.98 Xorg                      
29780 cnbiz850      20   0 2623m  44m  11m S   14  1.1   0:47.21 TradeBlazer.exe           
29783 cnbiz850      20   0  6028 3260  696 S    8  0.1   0:21.56 wineserver                                 
29731 cnbiz850      20   0  7080 4352  688 S    5  0.1   0:30.80 wineserver                
29800 cnbiz850      20   0 2610m  29m 7680 S    4  0.8   0:11.15 tbdatacenter.ex           
In the XP case then I ran VirtualBox on Desktop 4, kept mytrader2009 window on top, then did "top" on the same desktop. The numbers:

Code: Select all

  PID USER      	PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                   
30421 cnbiz850      20   0 1271m 653m 599m S   48 16.6   3:03.97 VirtualBox                
 1415 root      	20   0  299m  72m  47m S   24  1.8 101:33.25 Xorg                      
The total for Wine is 66% and the XP case is 48%. I didn't count the xorg numbers here. I only want to make a point with the xorg numbers below.

Now let's do some further measures.

Further case on XP. Now I keep the VBox intact on Desktop 4, but move the terminal window where I run "top" to Desktop 1. Now the numbers are as follows:

Code: Select all

  PID USER      	PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                   
30421 cnbiz850      20   0 1271m 653m 599m S   37 16.6   3:32.82 VirtualBox                                
 1415 root      	20   0  301m  73m  48m S    3  1.9 101:42.26 Xorg                      
Then, I went into XP on Desktop 4 and minimised the 2 app windows (I think this is the case I reported for the XP test on my first post), came back to Desktop 1 and the "top" gives the following numbers:

Code: Select all

  PID USER      	PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                   
30421 cnbiz850      20   0 1271m 653m 599m S   26 16.6   3:53.26 VirtualBox                              
 1415 root      	20   0  301m  73m  48m S    2  1.9 101:45.24 Xorg                      
Notice, by switching desktops, the number dropped from 48% to 37%. If the app windows were minimised in XP, then the number dropped further to 26%. Also notice the big drop of the xorg numbers from 24% to 2%.

Now if do the same things for the Wine case, the numbers are below.

Simply switch desktop:

Code: Select all

  PID USER      	PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                   
30654 cnbiz850      20   0 2667m 112m  15m R   16  2.9   1:11.06 mytrader2009.ex           
30958 cnbiz850      20   0 2632m  58m  11m S   15  1.5   0:14.82 TradeBlazer.exe           
31081 cnbiz850      20   0  6816 3860  704 R   11  0.1   0:06.70 wineserver                                   
30657 cnbiz850      20   0  7084 4368  692 S    7  0.1   0:46.65 wineserver                
 1415 root      	20   0  297m  69m  44m S    6  1.8 104:59.66 Xorg                      
31142 cnbiz850      20   0 2604m  28m  11m S    3  0.7   0:01.68 tbdatacenter.ex           
Minimise both app windows and then switch desktop:

Code: Select all

  PID USER      	PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                   
30654 cnbiz850      20   0 2667m 112m  15m S   17  2.9   1:25.34 mytrader2009.ex           
30958 cnbiz850      20   0 2632m  58m  11m R   14  1.5   0:26.30 TradeBlazer.exe           
31081 cnbiz850      20   0  7600 4780  708 S   10  0.1   0:15.17 wineserver                               
 1415 root      	20   0  297m  69m  44m S    6  1.8 105:07.25 Xorg                      
30657 cnbiz850      20   0  7084 4368  692 S    6  0.1   0:52.17 wineserver                
31142 cnbiz850      20   0 2604m  28m  11m S    2  0.7   0:03.32 tbdatacenter.ex           
The totals of the 2 sets of numbers not including those of xorg are: 52% and 49%. Switching desktops make some differences, but minimising windows makes no further difference. Switching desktops does make xorg number to drop from 22% to 6%.

In any case, the inclusion of the xorg numbers is important to reflect the end user's needs. After all, it is at his desire to see the resource usage drop when he puts the apps run at the background (by switching desktop and/or minimising the windows), so that he can use the resource to do something else.

So, if we count the xorg numbers, the total CPU usage changes from active running to inactive running are as follows. In the XP case, it is 72% (48%+24%) when active and 28% (26%+2%) when inactive. In the Wine case, it is 88% (66%+22%) when active and 55% (49%+6%)when inactive.

Can we conclude from these that Wine consumes substantially more CPU resources then running XP on VirtualBox? What can we get from these tests? Should that be at least the thinking of what are the causes of the inefficiencies in the Wine case? Maybe it is not Wine alone - could it also include things like Gnome, the window manager (I use Openbox on Gnome), Ubuntu, or Linux kernel. I don't know, but I do hope the efficiency can be improved.

As to memory usage, I think the number reported above for VirtualBox is not the actual usage by XP but rather the amount allocated by the user to the virtual machine. In my case, it is 512MB fixed - I don't know if there is a way for VirtualBox to use adjustable memory resource. Also I view memory usage differently from CPU usage. Memory is like disk space, and as long as I have enough, using more does not slow the computer down, and also it does not cause that much heat.
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

Well... you'd need the actual usage data captured during use over some time and looked at to really know whats gong on... but are you sure those are all the numbers for virtualbox? I do not have virtualbox installed (and do not want to)... but VMWare sure takes up more CPU usage for me than Wine, but is has several processes running, more than what your listing for virtualbox..

I think the problem might not be in Wine, since your Wine usage looks high, but in the program you are running in Wine. I run something simple like Notepad and average below 1% Total... The programs you are running might have some issue with some part of Wine that is causing more CPU usage.
cnbiz850
Level 3
Level 3
Posts: 65
Joined: Sun Nov 08, 2009 9:54 pm

Post by cnbiz850 »

Looks like there is only one significant process of VirtualBox - there is no other above 1% CPU that can possibly belong to VirtualBox during the tests.

The 2 apps I run are understandably much more CPU intensive than Notepad (which I feel can be a negligible process on modern computers). They are securities trading software somewhat like MetaTrader that many may know. They receive price information and update charts in real time. It involves communications and 2D graphics. While they are not 100% compatible with Wine, they perform normally under Wine - not too much unusual than under XP.
oiaohm
Level 8
Level 8
Posts: 1020
Joined: Fri Feb 29, 2008 2:54 am

Post by oiaohm »

cnbiz850 You are exposing a techical difference between Windows and Linux/Posix/Unix

Wine does not do the Windows manager job. Under windows there is a active window bias. Ie Active window gets more CPU time. Linux Windows managers don't do this. So what you are calling inactive is not as such.

minimising windows in Windows also causes them to lose CPU access. Linux not the case.

Yes I know is kinda shocking the scheduler will serve up more time to an application running in wine than in virtualbox. Its one of the reason why games run a lot better in wine at times than virtualbox.

Maybe one day Windows Managers under X11 will get smarter and adjust application biases when they don't have screen view.

"After all, it is at his desire to see the resource usage drop when he puts the apps run at the background (by switching desktop and/or minimising the windows), so that he can use the resource to do something else. "

This is a windows nature desire. Not a Unix or Posix one. Unix and Posix world does not link performance and displayed status.

Cgroup around applications can tell the scheduler to give processor less cpu time.
cnbiz850
Level 3
Level 3
Posts: 65
Joined: Sun Nov 08, 2009 9:54 pm

Post by cnbiz850 »

Thanks oiaohm for the reply. That clears up the questions.

Now Linux is more and more being adopted at the personal desktops, the active bias perhaps should be addressed soon. I hope someone in the Linux community must be considering it.
Frédéric Delanoy

Question on Wine CPU usage

Post by Frédéric Delanoy »

On Mon, Sep 5, 2011 at 02:53, cnbiz850 <[email protected]> wrote:
Thanks oiaohm for the reply.  That clears up the questions.

Now Linux is more and more being adopted at the personal desktops, the active bias perhaps should be addressed soon.  I hope someone in the Linux community must be considering it.
I very much doubt some with do that soon.
You can always adjust CPU priority with "renice" for the process you care about.
oiaohm
Level 8
Level 8
Posts: 1020
Joined: Fri Feb 29, 2008 2:54 am

Post by oiaohm »

Frédéric Delanoy no nice does not truly work that adjust time slice of program not the programs around it. Kinda a wing and a pray method that it will give the results you expect.

cnbiz850 yes there is something in the works that works not as integrated as well as it could be. ulatencyd https://github.com/poelzi/ulatencyd/ this can emulate the windows like behavior. Yes this is cgroup based tech so it works.

ulatencyd can set memory limits and other items on applications as well at runtime. So its the big stick to keep everything in line. That would be very useful with some of those bad behaved program on windows.

Linux people do normally embrace and idea and extend it to something better.
doh123
Level 8
Level 8
Posts: 1227
Joined: Tue Jul 14, 2009 1:21 pm

Post by doh123 »

I guess this is why my main Wine experiences are different since I mainly only use it in OSX, and it works like Windows, giving more resources to the foreground app and cutting off background apps unless they are trying to pull over a certain amount. I haven't used Linux for normal desktop tasks in a few years, so I guess I just kind of assumed it did this too.
oiaohm
Level 8
Level 8
Posts: 1020
Joined: Fri Feb 29, 2008 2:54 am

Post by oiaohm »

I forgot to mention ulatencyd integrates with systemd.

doh123 there are times that the foreground bias is a curse.

The issue is the left over effect of X11 yes the very old evil it is.

Due to X11 being cross platform it never had any controls for applications cpu access. Since cpu access owns the the kernel and is OS dependent.

Basically windows and OS X have something like ulatencyd hidden inside them. Linux is a little late to the party doing this.
Locked