alexleemanfui / disruptor4cpp Goto Github PK
View Code? Open in Web Editor NEWC++ port of LMAX disruptor
License: BSD 3-Clause "New" or "Revised" License
C++ port of LMAX disruptor
License: BSD 3-Clause "New" or "Revised" License
Why not implement a complete disruptor4, such as no workerprocessor
Hi,
just for anyone using this porting of the disruptor in C++11, including the author.
I have been using this otherwise excellent implementation and came across a bug when using it in multiple producer. There is a little big bug in this line:
https://github.com/alexleemanfui/disruptor4cpp/blob/master/include/disruptor4cpp/utils/util.h#L82
it should be:
((value / 2 == 1) ? 1 : log2(value / 2) + 1)
Notice the comparison to 1
instead of 0
.
Thanks,
Pablo.
I have found this fantastic work and applied it to my work successfully. Everything looks great, but there is one small thing : how to create and run multiple consumers with events from multiple producers on multiple threads? because the Java version seems to support these features, so what should i do if i want to use these features.
Demo performance problem, cpu takes 100%
modify test code,it works failed:
class int_handler : public disruptor4cpp::event_handler
{
public:
int_handler() = default;
virtual ~int_handler() = default;
virtual void on_start() { }
virtual void on_shutdown() { }
virtual void on_event(int& event, int64_t sequence, bool end_of_batch)
{
std::cout << "Received integer: " << event << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(10)); //----------modify----------
}
virtual void on_timeout(int64_t sequence) { }
virtual void on_event_exception(const std::exception& ex, int64_t sequence, int* event) { }
virtual void on_start_exception(const std::exception& ex) { }
virtual void on_shutdown_exception(const std::exception& ex) { }
};
int main(int argc, char* argv[])
{
using namespace disruptor4cpp;
// Create the ring buffer.
//ring_buffer<int, 1024, busy_spin_wait_strategy, producer_type::multi> ring_buffer;
//----------modify----------
ring_buffer<int, 64, busy_spin_wait_strategy, producer_type::multi> ring_buffer;
// Create and run the consumer on another thread.
auto barrier = ring_buffer.new_barrier();
int_handler handler;
batch_event_processor<decltype(ring_buffer)> processor(ring_buffer, std::move(barrier), handler);
std::thread processor_thread([&processor] { processor.run(); });
// Publish some integers.
for (int i = 0; i < 1000; i++)
{
int64_t seq = ring_buffer.next();
ring_buffer[seq] = i;
ring_buffer.publish(seq);
}
// Stop the consumer.
//----------modify----------
//std::this_thread::sleep_for(std::chrono::seconds(1));
//processor.halt();
processor_thread.join();
return 0;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.