CloudWatch 代理:批量大小等于“1”——这是个坏主意吗?

CloudWatch Agent: batch size equal to "1" - is it a bad idea?

如果我理解正确,CloudWatch 代理使用一种批处理将事件发布到 CloudWatch,其大小由 the two params:

指定
batch_count:

Specifies the max number of log events in a batch, up to 10000. The default value is 1000.

batch_size

Specifies the max size of log events in a batch, in bytes, up to 1048576 bytes. The default value is 32768 bytes. This size is calculated as the sum of all event messages in UTF-8, plus 26 bytes for each log event.

我想,为了消除在 EC2 实例终止的情况下丢失任何日志数据的可能性,batch_count 应该等于 1(因为在实例的情况下终止所有日志将被销毁)。我是对的,这只是实现它的一种方法,这对性能有何影响?它会有任何明显的副作用吗?

是的,这是个坏主意。您可能更有可能以这种方式丢失数据。 PutLogEvents API that the agent uses is limited to 5 requests per second per log stream (source)。 batch_count 为 1 时,您每秒只能发布 5 个日志事件。如果应用程序要始终如一地产生更多,代理将无法跟上。

如果您绝对不能丢失任何日志数据,也许您应该改为将该数据写入数据库。总是会有丢失日志数据的风险,即使 batch_count 为 1。在代理轮询日志文件之前,主机总是会崩溃......默认情况下,BTW 每 5 秒一次(source).