c***5 发帖数: 158 | 1 请问遇到复杂情况,你们如何DEBUG,有时很难用MOCK。 |
g*****g 发帖数: 34805 | 2 logging.
【在 c***5 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 请问遇到复杂情况,你们如何DEBUG,有时很难用MOCK。
|
b*******s 发帖数: 5216 | 3 logging changes execution seq as well
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : logging.
|
c*********e 发帖数: 16335 | 4 agree. also it slows down the application if u need to write a lot of log.
【在 b*******s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : logging changes execution seq as well
|
k****i 发帖数: 128 | |
g*****g 发帖数: 34805 | 6 if that's the case, your app should not be dependent on the seq or you have
a bug.
logging can have levels and be async. It should not impact performance
significantly.
【在 b*******s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : logging changes execution seq as well
|
r***s 发帖数: 737 | 7 A circular buffer in thread local storage.
in suspicious code paths, stick in small piece of information in that
circular buffer.
add assertions to verify your pre and post conditions.
when assertion fail, dump the thread local buffer to log.
【在 c*********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : agree. also it slows down the application if u need to write a lot of log.
|
r***s 发帖数: 737 | 8 Well, you also need to do divide and conquer, try to narrow down the scope
first, actually this idea can also be used to narrow down where are the
suspicious places.
【在 r***s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : A circular buffer in thread local storage. : in suspicious code paths, stick in small piece of information in that : circular buffer. : add assertions to verify your pre and post conditions. : when assertion fail, dump the thread local buffer to log.
|
b*******s 发帖数: 5216 | 9 I mean even you are with async logging. There's still at least one lock,
maybe invisible to you, in your logging system or you will receive some
chaos. It is not a trivial thing. It serializes some execution sequence.
have
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : if that's the case, your app should not be dependent on the seq or you have : a bug. : logging can have levels and be async. It should not impact performance : significantly.
|
g*****g 发帖数: 34805 | 10 Of course there's a lock, so that the logging is written sequentially. But
the log appending is non-blocking with a simple buffer. It's like a bounded
job queue. As long as you are not logging too fast it'll be OK.
【在 b*******s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : I mean even you are with async logging. There's still at least one lock, : maybe invisible to you, in your logging system or you will receive some : chaos. It is not a trivial thing. It serializes some execution sequence. : : have
|
|
|
b*******s 发帖数: 5216 | 11 A new lock has an impact in some scenarios. But we have some tricks to
overcome it.
bounded
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Of course there's a lock, so that the logging is written sequentially. But : the log appending is non-blocking with a simple buffer. It's like a bounded : job queue. As long as you are not logging too fast it'll be OK.
|
g*****g 发帖数: 34805 | 12 As I said, there's no lock in execution flow. The lock in log writing can
cause logging loss in worst case scenario.
【在 b*******s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : A new lock has an impact in some scenarios. But we have some tricks to : overcome it. : : bounded
|
b*******s 发帖数: 5216 | 13 You didn't get it
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : As I said, there's no lock in execution flow. The lock in log writing can : cause logging loss in worst case scenario.
|
g*****g 发帖数: 34805 | 14 No, you didn't get it.
【在 b*******s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : You didn't get it
|
r***s 发帖数: 737 | 15 楼主跑了就你们俩在这打架。
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : No, you didn't get it.
|
r***s 发帖数: 737 | 16 大牛们相互鄙视完了谁也不解释。
我来冲个大头说一下我知道的一点点
异步log无非就是用户程序写进内存buffer,另外一个异步的线程负责往外写。这个
buffer大部分
时候是多个线程共用的,问题在于如何不用锁来保护这个buffer?
先说用户程序里的多个线程都要写进一个buffer,怎么防止互相覆盖? buffer维护一
个指针
write_edge,要往里写的线程知道自己要写多少字节size,然后用 atomic increment
把这个指针
往右移动:interlocked_increment(&write_edge, size), 最后在这个指针左边写入。
这样可以保证不互相覆盖。
下一步看往外写的那个线程和其他线程如何同步。 buffer物理上是带状的,有开始和
结束。把它想象成一个逻辑环,有两个指针,read_edge和write_edge,每次有人写入
write_edge 右移,往外写Log的时候read_edge右移,只要保证read_edge一直在write_
edge 后面一定安全距离就可以了。
这个实现有些问题。 很多人认为世上没有真正lock free的东西,atomic increment只
是锁的一种形式而已,他跟锁一样用的是memory barrier,某些情况会导致线程执行顺
序改变。
【在 g*****g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : No, you didn't get it.
|
g*****g 发帖数: 34805 | 17 诸如ConcurrentLinkedQueue就是lock free queue,我都不知道这有啥好争的。
increment
【在 r***s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 大牛们相互鄙视完了谁也不解释。 : 我来冲个大头说一下我知道的一点点 : 异步log无非就是用户程序写进内存buffer,另外一个异步的线程负责往外写。这个 : buffer大部分 : 时候是多个线程共用的,问题在于如何不用锁来保护这个buffer? : 先说用户程序里的多个线程都要写进一个buffer,怎么防止互相覆盖? buffer维护一 : 个指针 : write_edge,要往里写的线程知道自己要写多少字节size,然后用 atomic increment : 把这个指针 : 往右移动:interlocked_increment(&write_edge, size), 最后在这个指针左边写入。
|