0

I have a multi index in shared memory.

I need to dump the content of multi index to csv.

So each action on the multi index is protected by a mutex lock.

So the way i did the dump, is lock the mutex, loop through a specific list index and write entries to file.

The problem is that it takes too much time. Is there a way (and will it be faster) to copy the shared memory content, free the mutex, and then analyze the copied memory? I didn't find how to copy the shared memory content if possible (as it is not a POD type)

m_pSegment->find_or_construct<MultiIndexType>("MultiIndex")(
        typename MultiIndexType::ctor_args_list(),
        typename MultiIndexType::allocator_type(m_pSegment->get_segment_manager()));

find_or_construct return the memory pointer.

Here is a link to code http://coliru.stacked-crooked.com/a/09ea79752512fad8

In coliru no output perhaps because it is in shared memory.

yaron
  • 439
  • 6
  • 16

1 Answers1

1

Writing to a file is a slow business, much more so if you're using iostreams. You can copy the contents you're interested in to an auxiliary vector while within the mutex:

std::vector<uint64_t> IMSIs;
IMSIs.reserve(hash->size());
for(const auto& v: hash->get<My_TIMESTAMP_tag>()) IMSIs.push_back(v.IMSI);

and the process the vector for printing outside the mutex.

Joaquín M López Muñoz
  • 5,243
  • 1
  • 15
  • 20
  • yes, i come to this conclusion also, but perhaps copying the full shared memory without iterating over elements could be faster? – yaron Apr 09 '18 at 09:39
  • 1
    The problem with copying the memory block is that reconstructing an iterable `multi_index_container` from copied memory looks extremely complex. – Joaquín M López Muñoz Apr 09 '18 at 09:55