Code Monkey home page Code Monkey logo

disruptorplus's People

Contributors

lewissbaker avatar saltzm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

disruptorplus's Issues

Performance defect in disruptorplus::spin_wait ctor

The constructor of class disruptorplus::spin_wait has the call to std::thread::hardware_concurrency(). It affects latency of all
disruptorplus::spin_wait_strategy::wait_until_published() methods:

spin_wait()
{
reset();
}
/// \brief
/// Reset the spin_wait back to its original state.
void reset()
{
m_value = std::thread::hardware_concurrency() > 1 ? 0 : 10;
}

sequence_t wait_until_published(
sequence_t sequence,
size_t count,
const std::atomic<sequence_t>* const sequences[])
{
assert(count > 0);
spin_wait spinner;
sequence_t result = minimum_sequence_after(sequence, count, sequences);
while (difference(result, sequence) < 0)
{
spinner.spin_once();
result = minimum_sequence_after(sequence, count, sequences);
}
return result;
}

template<typename Clock, typename Duration>
sequence_t wait_until_published(
sequence_t sequence,
size_t count,
const std::atomic<sequence_t>* const sequences[],
const std::chrono::time_point<Clock, Duration>& timeoutTime)
{
assert(count > 0);
spin_wait spinner;
sequence_t result = minimum_sequence_after(sequence, count, sequences);
while (difference(result, sequence) < 0)
{
if (spinner.next_spin_will_yield() && timeoutTime < Clock::now())
{
// Out of time.
return result;
}
spinner.spin_once();
result = minimum_sequence_after(sequence, count, sequences);
}
return result;
}

Also, there are some redundant code which trying to hide negative impact of this defect:

size_t count = m_sequences.size();
sequence_t current = minimum_sequence_after(sequence, count, m_sequences.data());
if (difference(current, sequence) >= 0)
{
return current;
}

size_t count = m_sequences.size();
sequence_t current = minimum_sequence_after(sequence, count, m_sequences.data());
if (difference(current, sequence) >= 0)
{
return current;
}

Possible fix is to save the result of std::thread::hardware_concurrency() in some static variable and reuse it in spin_wait ctor.

Add CMake Support

Nice work! I was able to compile example 1 with CMake. We can add CMake support for others.

Footnotes

  1. Small typo in README: sequence_t seq = claimStrategy.claim_one(): // <<< Should be ; and missing <iostream> header, see PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.