Coder Social home page Coder Social logo

Comments (8)

CodingHanYa avatar CodingHanYa commented on May 20, 2024 1

具体还有很多影响因素,但目前我认为性能下降的原因最终还是归结到加剧了竞争或者是调用自旋锁时延长了锁的占用时间。只要不触犯这两条,基本上问题就不大。感谢您的认可,向您学习。

from workspace.

CodingHanYa avatar CodingHanYa commented on May 20, 2024

已在文档说明

from workspace.

ChunelFeng avatar ChunelFeng commented on May 20, 2024

看来从理论和实际上,都能得出结论,这种 batch 替换的方式,比直接写入队列 然后去拿,效果好了不少。

我之前尝试过,依次写入队列,然后获取的时候,修改为 获取多个task 去执行的思路。
尝试下来,在空跑的测试环境中,性能是下降的。
预计是在任务有random耗时的情况下, 性能会略有提升。
但是由于纯调度的性能diff,本来就非常小,在有耗时的task的情况下,会被稀释的很厉害。
测试结果就不是那么准确了。

感谢您的回复,希望可以添加到你的个人微信,以便今后经常咨询和讨论。
我的微信是 ChunelFeng

from workspace.

infdahai avatar infdahai commented on May 20, 2024

无锁 性能会比 自旋锁 性能高吗

from workspace.

infdahai avatar infdahai commented on May 20, 2024

哦,是我理解错了。 如果测试程序锁竞争导致的cache coherency traffic中比较大,可以试试ttas锁。https://rigtorp.se/spinlock/。 不知道性能提升怎么样了。

from workspace.

infdahai avatar infdahai commented on May 20, 2024

我可以试着提个Pr

from workspace.

infdahai avatar infdahai commented on May 20, 2024

我试了下 https://probablydance.com/2019/12/30/measuring-mutexes-spinlocks-and-how-bad-the-linux-scheduler-really-is/ 这篇文章提到的改进,没什么效果。

struct spinlock {
  void lock() {
    for (int spin_count = 0; !try_lock(); ++spin_count) {
      if (spin_count < 16)
        _mm_pause();
      else {
        std::this_thread::yield();
        spin_count = 0;
      }
    }
  }
  bool try_lock() {
    return !locked.load(std::memory_order_relaxed) &&
           !locked.exchange(true, std::memory_order_acquire);
  }
  void unlock() { locked.store(false, std::memory_order_release); }

 private:
  std::atomic_bool locked{false};
};

from workspace.

CodingHanYa avatar CodingHanYa commented on May 20, 2024

如果用极少的异步线程,且每次推任务时采用批量提交大量的任务(延长锁的占用时间),那么采用这种自旋锁才有可能能提高整体性能,否则可能会因为多做一些无用的yeild导致线程切换从而降低整体性能。

from workspace.

Related Issues (20)

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.