forked from Abc-Arbitrage/Disruptor-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneToOneRawBatchThroughputTest.cpp
More file actions
88 lines (72 loc) · 2.47 KB
/
Copy pathOneToOneRawBatchThroughputTest.cpp
File metadata and controls
88 lines (72 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "stdafx.h"
#include "OneToOneRawBatchThroughputTest.h"
namespace Disruptor
{
namespace PerfTests
{
OneToOneRawBatchThroughputTest::OneToOneRawBatchThroughputTest()
{
m_myRunnable = std::make_shared< MyRunnable >(m_sequencer);
m_sequencer->addGatingSequences({ m_myRunnable->sequence });
}
std::int64_t OneToOneRawBatchThroughputTest::run(Stopwatch& stopwatch)
{
std::int32_t batchSize = 10;
auto latch = std::make_shared< Tests::ManualResetEvent >(false);
auto expectedCount = m_myRunnable->sequence->value() + m_iterations * batchSize;
m_myRunnable->reset(latch, expectedCount);
std::thread([this] { m_myRunnable->run(); }).detach();
stopwatch.start();
auto sequencer = m_sequencer;
for (std::int64_t i = 0; i < m_iterations; i++)
{
auto next = sequencer->next(batchSize);
sequencer->publish(next - (batchSize - 1), next);
}
latch->waitOne();
stopwatch.stop();
waitForEventProcessorSequence(expectedCount);
return m_iterations * batchSize;
}
std::int32_t OneToOneRawBatchThroughputTest::requiredProcessorCount() const
{
return 2;
}
void OneToOneRawBatchThroughputTest::waitForEventProcessorSequence(std::int64_t expectedCount)
{
while (m_myRunnable->sequence->value() != expectedCount)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
OneToOneRawBatchThroughputTest::MyRunnable::MyRunnable(const std::shared_ptr< ISequencer< boost::any > >& sequencer)
{
m_barrier = sequencer->newBarrier({});
}
void OneToOneRawBatchThroughputTest::MyRunnable::reset(const std::shared_ptr< Tests::ManualResetEvent >& latch, std::int64_t expectedCount)
{
m_latch = latch;
m_expectedCount = expectedCount;
}
void OneToOneRawBatchThroughputTest::MyRunnable::run()
{
auto expected = m_expectedCount;
try
{
std::int64_t processed;
do
{
processed = m_barrier->waitFor(sequence->value() + 1);
sequence->setValue(processed);
}
while (processed < expected);
m_latch->set();
sequence->setValue(processed);
}
catch (std::exception& ex)
{
std::cout << ex.what() << std::endl;
}
}
} // namespace PerfTests
} // namespace Disruptor