Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost interprocess containers - performance issue
From: Naveen Santhapuri (naveenu_at_[hidden])
Date: 2012-03-11 22:54:41


> Date: Sun, 11 Mar 2012 12:21:36 +0100
> From: Ion Gazta?aga <igaztanaga_at_[hidden]>
> To: Boost User List <boost-users_at_[hidden]>
> Subject: Re: [Boost-users] Boost interprocess containers - performance
       issue
> Message-ID: <4F5C8AC0.9020508_at_[hidden]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed

>El 11/03/2012 1:00, Naveen Santhapuri escribi?:
>> Hello all,
>>
>> I am experimenting with Boost interprocess containers and like the
>> ease of using them. I want to use these in place of the "linux shared
>> memory+shared memory allocator + std containers". However, I am seeing
>> some performance hit when using boost. I measured the times for vector
>> access from shared memory. I define access as indexing into the vector
>> (v[i]) (all times in milli seconds):
>>
>> Num elements Local heap | Boost ipc | Shmat()
>> 100,000 0.23 0.39 0.27
>> 1,000,000 2.3 3.85 2.7

> What does Shmat mean? Are you putting a std::vector directly in a shared
> memory segment?

> Obviously if you put boost containers in shared memory you don't store
> raw pointers (as every process can map the memory in a different
> address, making raw pointers unusable). When using offset_ptr we have a
> performance hit as we need to calculate the real address computing a
> pointer arithmetic (this + stored offset). Apart from that, as
> offset_ptr relies on undefined behaviour, the offset calculation must be
> marked as non-inlineable in most compilers, increasing the performance
> hit. I think it can be improved using some kind of compiler-specific
> annotations or assembler, but I have no skills to do that nowadays.
>
> Best,
>
> Ion

Thank you for the reply Ion. Re: shmat() - Yes, I am creating a std::vector
with shared allocator in shared memory.

My use case: One executable (lets call it shvec) writes std containers to
shared memory. Another instance of shvec reads those containers from shared
memory. I want to do this to preload a large amount of data into memory,
before my service starts, so that the start time of the service can be cut
down.

I want to use boost but I am afraid of the runtime hit. Even with the
offset pointer, do the numbers above make sense (as much as 70% extra
time)?

My alternative strategy without boost ipc:
I will be running on 64bit linux and hoping to map the shared memory
segment to the same location in all instances using shmat(). To achieve
that, the first instance gets the shared memory segment address, which will
be used by the other instances that read from the shared memory. If I can
map them to the same address, can I use raw pointers without any problem?

Naveen



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net