[Barrelfish-users] C++ standard library performance issue

Jialin Li nick.lijl at gmail.com
Wed Oct 21 19:07:49 CEST 2015


Hi Zaheer,

Thank you for your response. The dmalloc allocator magically solves the 
problem! I didn't realize the memory allocator could cause such a huge 
performance degradation. dmalloc occasionally gives me "usage error 
action", but not affecting program execution.

Thanks a lot for the help,
Jialin


On 10/20/2015 03:58 PM, Zaheer Chothia wrote:
> Hi Jialin,
>
> Rather than the data structure itself, my intial suspicion would lie
> with one of:
> * Random number generation (due to newlib vs. glibc)
> * String copy constructor (== malloc + memcpy).  The default allocator in
>    oldc is horribly slow; have a look at `lib/dmalloc/README.barrelfish`
>    and try that for comparison.
> More fine-grained timing may help tease these apart.  (I should also
> mention I have not tried running the code at all!)
>
> I imagine the hash map plays less of a role.  Reasoning: since you are
> using the external toolchain it will link against libstdc++ which is
> the same implementation as on Linux (discounting version differences).
> On Barrelfish, C++ programs can also be compiled with Hake which will
> instead use LLVM's libc++.  If you want to try this have a look at
> `usr/tests/cxx/`.
>
> Hope that helps.
> --Zaheer
>
> On Tue, Oct 20, 2015 at 12:07 AM, Jialin Li <nick.lijl at gmail.com> wrote:
>> Hi,
>>
>> I'm running a server application on barrelfish(actually Arrakis). The server
>> has to store some key value pairs so I used the standard library
>> std::unordered_map. However, I was observing the server latency getting
>> higher over time (with more key value pairs installed), from ~10us to a few
>> ms. I wrote a toy program (shown below) just to validate the result. For the
>> toy program, I also observed there are latency spikes every few operations,
>> and the latency spike increases over time. I tried the same program on Linux
>> and not seeing the same problem. For the C++ compiler, I am using
>> tools/build-toolchain.sh, which I also attached.
>>
>> --------------------------
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <string.h>
>> #include <sys/time.h>
>> #include <unordered_map>
>> #include <list>
>> #include <string>
>>
>> #define ITERATION 50000
>>
>> using namespace std;
>>
>> void randString(char * buffer, int len) {
>>    for (int i = 0; i < len - 1; i++) {
>>      buffer[i] = '0'+(random()%74);
>>    }
>> }
>>
>> int main() {
>>    unordered_map<string, string> store;
>>    char keybuf[32];
>>    char valuebuf[128];
>>    struct timeval st, ed;
>>    memset(keybuf, 0, 32);
>>    memset(valuebuf, 0, 128);
>>    long int result;
>>    unsigned long before, after;
>>
>>    for (long int k = 0; k < ITERATION; k++) {
>>      gettimeofday(&st, NULL);
>>      randString(keybuf, 32);
>>      randString(valuebuf, 128);
>>
>>      string key(keybuf);
>>      string value(valuebuf);
>>      store[key] = value;
>>
>>      gettimeofday(&ed, NULL);
>>
>>      printf("latency %lu\n",
>> (ed.tv_sec-st.tv_sec)*1000000+ed.tv_usec-st.tv_usec);
>>    }
>> }
>>
>>
>> Let me know if any more information is needed. Thanks in advance for the
>> help.
>>
>> Jialin
>>
>> _______________________________________________
>> Barrelfish-users mailing list
>> Barrelfish-users at lists.inf.ethz.ch
>> https://lists.inf.ethz.ch/mailman/listinfo/barrelfish-users
>>



More information about the Barrelfish-users mailing list