strange slowing down of C++ allocs
Asked Answered
I

1

9

Could someone please tell me why following things could happen:

I have 2 computers:

  1. my working comp
  2. Server

I maintain C++ program (msvc 2005 c++ compiled) that works too slow only on server, but not on my comp.

I conducted measurements (GetThreadTimes and so on) and could definitely say that the narrow place - its memory allocation (new/malloc). And it happens only on server!

I could claim that it happens due to memory fragmentation because of 1st time server instance of program works fine, its start loosing time on allocs only after data reload again into memory (1-1.5 million allocs/frees).

I wouldnt be so surprised if I see the same behaviour due to memory fragmentation on both computers (my comp and server) but what I see is: 1). on my comp allocations take ~5% of time (not exact but someting like that) 2). on the server these allocs takes ~75% of time

how this could happen? What could slow down C++ allocations on Server computer, meanwhile its OK for my workstation. Where could be difference? Probably its something connected with OS-level memory management functions? because the C++ level manager the same in both cases.

Here is both configurations:

1). My computer (where allocs take ~5%):

OS Name:                   Microsoft Windows 7 Enterprise 
OS Version:                6.1.7600 N/A Build 7600
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          Windows User
Original Install Date:     16/09/2011, 19:37:43
System Boot Time:          05/04/2013, 11:58:11
System Model:              7304A58
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 23 Stepping 10 GenuineIntel ~2642 Mhz
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume2
System Locale:             ru;Russian
Input Locale:              en-us;English (United States)
Total Physical Memory:     4,061 MB
Available Physical Memory: 872 MB
Virtual Memory: Max Size:  8,121 MB
Virtual Memory: Available: 4,579 MB
Virtual Memory: In Use:    3,542 MB
Page File Location(s):     C:\pagefile.sys

2). Server (where allocs take ~75%):

OS Name:                   Microsoft(R) Windows(R) Server 2003, Enterprise Edition
OS Version:                5.2.3790 Service Pack 2 Build 3790
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Server
OS Build Type:             Multiprocessor Free
Original Install Date:     11/12/2008, 01:22:57
System Up Time:            1 Days, 8 Hours, 35 Minutes, 52 Seconds
System Manufacturer:       HP
System Model:              ProLiant BL685c G5  
System Type:               X86-based PC
Processor(s):              4 Processor(s) Installed.
                           [01]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
                           [02]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
                           [03]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
                           [04]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
Windows Directory:         C:\WINNT
System Directory:          C:\WINNT\system32
Boot Device:               \Device\HarddiskVolume1
Total Physical Memory:     65,534 MB
Available Physical Memory: 61,284 MB
Page File: Max Size:       97,696 MB
Page File: Available:      93,445 MB
Page File: In Use:         4,251 MB
Page File Location(s):     C:\pagefile.sys
                           D:\pagefile1\pagefile.sys
                           D:\pagefile2\pagefile.sys
                           D:\pagefile3\pagefile.sys
                           D:\pagefile4\pagefile.sys
                           D:\pagefile5\pagefile.sys
                           D:\pagefile6\pagefile.sys
                           D:\pagefile7\pagefile.sys

Will be grateful for clarifying this issue.

Ignite answered 5/4, 2013 at 16:1 Comment(2)
Are you using the same dataset on both machines?Assure
no, but comparable. my comp has ~ 260 000 items at works fluently, server comp experiencing difficulties at ~350 000 and more items it even starts to working hard even during load 1st 100 000 items.Ignite
H
4

The problem could be that the memory functions use only one mutex to lock the memory for allocation and freeing.

Hazelton answered 5/4, 2013 at 16:14 Comment(4)
MSVC++ 2005 isn't exactly the newest version, nor is Server 2003. The Windows 7 machine has the Low Fragmentation Heap enabled by default. This is therefore quite a believable answer. I'd expect newer versions to work much better with 4x4 core machines. As a workaround, try another allocator such as e.g. jemallocSeddon
Interesting. And quoting from this thread (#4859763 "...OS heap functions will perform rather well if the low-fragmentation heap is enabled, which it is by default since Windows Vista (on Windows XP it can be enabled by the application with a simple call to HeapSetInformation()). And with the LFH enabled, the performance of the Windows heap is comparable to the fastest available other allocators"Corps
thanks, will consider jemalloc, probably it will help, but not sure that it will be accepted by my chief :)Ignite
Many thanks for LFH. Wrote a little alloc test for millions of allocs and saw the difference for MSVC++ 2005 on windows XP (with and without LFH flag to be set manually). difference in speed is 2-10 times. By the way, MSVC++ 2010 CRT is set this LFH flag automatically and no need to call HeapSetInformation() manually. So this effect happens for MSVC++ 2005 + Win XP or Win 2003 server (old OS).Ignite

© 2022 - 2024 — McMap. All rights reserved.