Count distinct elements from a concurrently read stream [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have multiple listeners threads reading a stream of messages (Kafka). Each message has an identifier. The consumers/stream guarantees at-least once consumption. At most of the time, the stream would provide the message exactly once. The count of messages to expect is known beforehand. When all messages are received, I want to shutdown all listener threads. The number of messages can be at most 50 million. What data structure is most suitable for this?
I was thinking of using std::set, std::map and using a mutex at each insertion of the thread. Can a single thread be actually faster in such a use-case? Is there something more optimal?

std::unordered_map would be better. But you should consider using something like HyperLogLog

Related

How can I transfer std::multimap data over socket [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a std::multimap variable containing key-value data, and want to transfer it to a remote server over socket.
I known, in Java, we can serialize the object as byte stream and transfer it.
However, can I do the same thing in C++?
If not, how can I transfer std::multimap data over socket in C++?
Meanwhile, are there some other methods to transfer std::multimap data over socket without serialization, or using 3rd library?
Thanks in advance!
It can be done through boost::serialization, STL collection of it can be found here

Usrp Full Duplex Operation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a USRP N200 with WBX daughterboard. I'd need a simple C/C++
program that can simultaneously receive and transmit. but I can't find It.
Look at the examples that come with UHD. There's the txrx loopback example which does exactly that.
In essence, it's not complicated:
spawn a thread for receiving and one for transmitting. This is optional, but it will make your system much less prone to receive sample over- or transmit sample underruns.
create an rx_streamer and a tx_streamer
In the RX thread, call the rx_streamer->recv() method repeatedly in the TX thread, tx_streamer->send() method repeatedly.

non-blocking communications in MPI: order of messages [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What happens if a processors sends exactly the same message to the same destination with the same tag? When the receiver wants to read it, does it read the last one?
What if two different processors send the same message (same tag) to one processor? which one it receive and in what order?
3- How we can know how many pending messages from a specific processor are in the queue in order to receive all of them?

Thread Loop with Sleep() or SetTimer [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have an Win32 app that contains 13 SetTimer() calls... I have a doubt: to optimize application performance, would be better to use CreateThread (with infinite loop and Sleep) instead SetTimer? Which of the two ways to a better way and timing of actions?
Sorry for bad english, thanks in advance!
I wouldn't write a custom timer unless you have a very specific need to do so. I'd guess performance difference would be negligible for most applications. Plus you'll run into other issues I'm sure you're not currently considering, like data synchronization, communicating with your GUI thread for user interactions, etc. It's possible you could even make performance worse.
If you feel you have a specific need, state what that need is and maybe we can guide the answer.

how to minimal WAN data transfer delay time? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have some idea about file remote location.Can i split a file in to chunks and use thread control split and socket to implement split data and send meanwhile ?
Besides, local can prefetch remote chunk and read it by two thread?
If you have one source of data and one sink I would assume that chunking won't help.
The IP-stack itself uses this method, so as long as you can provide data fast enough to the TCP stack (write buffer) and are fast enough reading the data from the buffer (read buffer) I think that is as fast as it gets...