Fabric出塊時間配置
Fabric出塊是將一個或者多個交易數據結構(即Envelope
)打包成區塊,這項工作由orderer
節點完成。目前fabric配置文件(configtx-template.yaml
)中的默認出塊時間為2s
。
相關參數
若需要修改fabric的出塊機制,則需要調整以下配置參數:
BatchTimeout
:出塊超時時間,最長出塊間隔(但緩存中必須含有數據才會出塊,否則無法出塊,即fabric不會強行產生空塊)MaxMessageCount
:區塊最大交易數量,當交易數量達到此參數后,會立即出塊。PreferredMaxBytes
:區塊首選字節數,正常情況下一個區塊中的交易數據大小會小於此參數。AbsoluteMaxBytes
:區塊最大字節數:所有情況下區塊的最大允許字節數,超過此參數的交易將無法打包,直接退回。
出塊機制和條件
基於上述指標,orderer
會在兩種條件下打包區塊:
- 定時觸發:維護以
BatchTimeout
為間隔的鬧鍾,定時檢測緩存中是否還有未出塊的交易,如果有則打包出塊; - 新交易觸發:當滿足條件的新交易與緩存中的交易大小之和與
PreferredMaxBytes
進行比較,超過此限制則將緩存中的交易進行打包,新交易進入緩存。或者交易數目超過MaxMessageCount
,也會進行打包。
默認參數配置
在fabric-starter
中,參數配置主要在configtx-template.yaml
文件中,與出塊時間相關的參數及其默認值如下:
# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 2s
# Batch Size: Controls the number of messages batched into a block
BatchSize:
# Max Message Count: The maximum number of messages to permit in a batch
MaxMessageCount: 10
# Absolute Max Bytes: The absolute maximum number of bytes allowed for
# the serialized messages in a batch.
AbsoluteMaxBytes: 98 MB
# Preferred Max Bytes: The preferred maximum number of bytes allowed for
# the serialized messages in a batch. A message larger than the preferred
# max bytes will result in a batch larger than preferred max bytes.
PreferredMaxBytes: 512 KB
參考博客
堅持不懈地努力才能成為大神!