我正在做Kafka的性能测试,需要测试不同的大型模式。目前,我正在研究基于 Avro 的负载测试。
通常,在使用 Kafka 时,您拥有数据并从中生成模式。我必须在这种情况下测试多个模式,而我不拥有这些模式的数据。我需要根据现有架构生成示例 Avro 数据。
有哪些可能的解决方案?
尝试过的解决方案:
如何根据现有的Avro schema生成样本数据?
如果您熟悉 Python,
fastavro
库提供了从架构生成数据的实用程序:https://fastavro.readthedocs.io/en/latest/utils.html
举个例子:
from fastavro.utils import generate_many
schema = {
'doc': 'A weather reading.',
'name': 'Weather',
'namespace': 'test',
'type': 'record',
'fields': [
{'name': 'station', 'type': 'string'},
{'name': 'time', 'type': 'long'},
{'name': 'temp', 'type': 'int'},
],
}
print(list(generate_many(schema, 5)))