【问题标题】:Beego NewLogger channelLens valueBeego NewLogger channelLens 值
【发布时间】:2022-01-16 15:36:53
【问题描述】:

谁能帮我理解channelLens 值在Beego NewLogger 函数中的意义。文档说channelLen means the number of messages in chan(used where asynchronous is true). if the buffering chan is full, logger adapters write to file or other way. & 我不清楚。提前致谢

【问题讨论】:

    标签: go logging beego


    【解决方案1】:

    当您不向 NewLogger() 传递任何参数时,它使用 defaultAsyncMsgLen 作为内部通道大小。本行:https://github.com/astaxie/beego/blob/v1.12.3/logs/log.go#L151

    当您传递参数时,记录器将其用作内部通道大小。

    【讨论】:

    • 感谢您的回答。但是我已经理解了您在文档中分享的观点。我的问题的意思是 channelLens 值的影响是什么?内存方面和性能方面?我(或开发人员)如何决定在这里给出哪个值?
    • channelLens 值取决于您的用例。这个记录器有一个 goroutine 文件编写器。例如,http 服务器有 N 个 goroutine,每个 goroutine 写入 2 条消息。然后 chanlen 应该大于 N*2 以防止在记录器执行文件轮换等长期操作时延迟客户端。如果 logger 有 smtpoutput 默认值可能没问题,因为 logger 无论如何都会阻塞 goroutine,因为 smtp 发送很慢。
    • 消耗的内存应该是 channelLens*12*average_logmsg_len 字节。 (12 为空字符串大小)
    猜你喜欢
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多