Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
avro php library benchmark
<?php
require_once('../lib/avro.php');
function create_record() {
$rec = array('member_id' => 1392, 'member_id2' => 999);
for ($i = 0; $i < 20; $i++) {
$rec['field' . $i] = 'test_value' . $i;
}
return $rec;
}
function create_writer() {
$schema_json = <<<_JSON
{"name":"member",
"type":"record",
"fields":[
{"name":"member_id", "type":"int"},
_JSON;
for ($i = 0; $i < 20; $i++) {
$schema_json .= '{"name":"field' . $i . '", "type":"string"},';
}
$schema_json .= '{"name":"member_id2", "type":"int"}]}';
$schema = AvroSchema::parse($schema_json);
$writer = new AvroIODatumWriter($schema);
return $writer;
}
for ($i = 0; $i < 10000; $i++) {
$writer = apc_fetch("writer");
if ($writer === false) {
$writer = create_writer();
apc_store("writer", $writer);
}
$io = new AvroStringIO();
$encoder = new AvroIOBinaryEncoder($io);
$writer->write(create_record(), $encoder);
$binary_string = $io->string();
// file_put_contents("/tmp/avro.log", $binary_string, FILE_APPEND);
}
<?php
// ab -n 10000 -c 10 http://url/to/avro_nginx_test.php
require_once('../lib/avro.php');
function create_record() {
$rec = array('member_id' => 1392, 'member_id2' => 999);
for ($i = 0; $i < 100; $i++) {
$rec['field' . $i] = 'test_value' . $i;
}
return $rec;
}
function create_writer() {
$schema_json = <<<_JSON
{"name":"member",
"type":"record",
"fields":[
{"name":"member_id", "type":"int"},
_JSON;
for ($i = 0; $i < 100; $i++) {
$schema_json .= '{"name":"field' . $i . '", "type":"string"},';
$jose['field' . $i] = 'test_value' . $i;
}
$schema_json .= '{"name":"member_id2", "type":"int"}]}';
$schema = AvroSchema::parse($schema_json);
$writer = new AvroIODatumWriter($schema);
return $writer;
}
$writer = apc_fetch("writer");
if ($writer === false) {
$writer = create_writer();
apc_store("writer", $writer);
}
$io = new AvroStringIO();
$encoder = new AvroIOBinaryEncoder($io);
$writer->write(create_record(), $encoder);
$binary_string = $io->string();
file_put_contents("/tmp/avro.log", AvroIOBinaryEncoder::encode_long(strlen($binary_string)) . $binary_string, FILE_APPEND);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment