由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - how to debug
相关主题
每秒500万这样的deadlock如何debug?
goodbug又丢人了node promise发出reject之后,是不是只能hit catch block ?
请教一个Node.js的疑惑Python 多线程或多进程如何搞
服务器端纯的asio的异步怎么写?类似vc问题:在Debug版本成功;在Release版本link失败
看了一下C#的async await面试题:debug: 函数return to a wrong place
做了一个测试说的再清楚一点: 抢票机性能只和中途停靠总站数相关
哥决定常驻这个版了我来写个老魏的详细实现方案。(更新了缺点)
fast loggingPython里边file writer的问题
相关话题的讨论汇总
话题: logging话题: debug话题: buffer话题: lock话题: log
进入Programming版参与讨论
1 (共1页)
c***5
发帖数: 158
1
请问遇到复杂情况,你们如何DEBUG,有时很难用MOCK。
g*****g
发帖数: 34805
2
logging.

【在 c***5 的大作中提到】
: 请问遇到复杂情况,你们如何DEBUG,有时很难用MOCK。
b*******s
发帖数: 5216
3
logging changes execution seq as well

【在 g*****g 的大作中提到】
: logging.
c*********e
发帖数: 16335
4
agree. also it slows down the application if u need to write a lot of log.

【在 b*******s 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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

相关主题
做了一个测试这样的deadlock如何debug?
哥决定常驻这个版了node promise发出reject之后,是不是只能hit catch block ?
fast loggingPython 多线程或多进程如何搞
进入Programming版参与讨论
b*******s
发帖数: 5216
11
A new lock has an impact in some scenarios. But we have some tricks to
overcome it.

bounded

【在 g*****g 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: You didn't get it
r***s
发帖数: 737
15
楼主跑了就你们俩在这打架。

【在 g*****g 的大作中提到】
: 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 的大作中提到】
: No, you didn't get it.
g*****g
发帖数: 34805
17
诸如ConcurrentLinkedQueue就是lock free queue,我都不知道这有啥好争的。

increment

【在 r***s 的大作中提到】
: 大牛们相互鄙视完了谁也不解释。
: 我来冲个大头说一下我知道的一点点
: 异步log无非就是用户程序写进内存buffer,另外一个异步的线程负责往外写。这个
: buffer大部分
: 时候是多个线程共用的,问题在于如何不用锁来保护这个buffer?
: 先说用户程序里的多个线程都要写进一个buffer,怎么防止互相覆盖? buffer维护一
: 个指针
: write_edge,要往里写的线程知道自己要写多少字节size,然后用 atomic increment
: 把这个指针
: 往右移动:interlocked_increment(&write_edge, size), 最后在这个指针左边写入。

1 (共1页)
进入Programming版参与讨论
相关主题
Python里边file writer的问题看了一下C#的async await
一个C++语法问题做了一个测试
一个multithreading 问题哥决定常驻这个版了
post incrementfast logging
每秒500万这样的deadlock如何debug?
goodbug又丢人了node promise发出reject之后,是不是只能hit catch block ?
请教一个Node.js的疑惑Python 多线程或多进程如何搞
服务器端纯的asio的异步怎么写?类似vc问题:在Debug版本成功;在Release版本link失败
相关话题的讨论汇总
话题: logging话题: debug话题: buffer话题: lock话题: log