Skip to content

Instantly share code, notes, and snippets.

@walf443

walf443/cli.php Secret

Created March 16, 2023 01:56
Show Gist options
  • Save walf443/498de51af5f09b08f20666b0e872aa76 to your computer and use it in GitHub Desktop.
Save walf443/498de51af5f09b08f20666b0e872aa76 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
require 'common.php';
use Google\Cloud\Bigtable\BigtableClient;
$bigtable = new BigtableClient();
$table = $bigtable->table('instanceId', 'tableId');
$keys = [];
$rows = $table->readRows([])->readAll();
foreach ($rows as $k => $row) {
$keys[] = $k;
}
unset($bigtable);
unset($table);
$bigtable = new BigtableClient();
$table = $bigtable->table('instanceId', 'tableId');
for($i = 0; $i < 50; $i++) {
$index = $keys[array_rand($keys)];
$start = hrtime(true);
$table->readRow($index);
$end = hrtime(true);
echo (($end - $start)/1000000),"ms\n";
}
package main
import (
"context"
"fmt"
"math/rand"
"time"
"cloud.google.com/go/bigtable"
)
func readRow(table *bigtable.Table, ctx context.Context, index string) time.Duration {
start := time.Now()
_, err := table.ReadRow(ctx, index)
if err != nil {
panic(err)
}
end := time.Now()
return end.Sub(start)
}
func main() {
ctx := context.Background()
client, err := bigtable.NewClient(ctx, "projectId", "instanceId")
if err != nil {
panic(err)
}
rr := bigtable.PrefixRange("")
table := client.Open("tableId")
keys := make([]string, 1)
err = table.ReadRows(ctx, rr, func(r bigtable.Row) bool {
keys = append(keys, r.Key())
return true
})
if err != nil {
panic(err)
}
keyCount := len(keys)
for i := 0; i < 50; i++ {
latency := readRow(table, ctx, keys[rand.Intn(keyCount)])
fmt.Println(float64(latency.Microseconds()) / 1000)
}
client.Close()
}
<?php
require 'vendor/autoload.php';
use Google\Cloud\Bigtable\BigtableClient;
$start = hrtime(true);
$bigtable = new BigtableClient();
$table = $bigtable->table('instanceId', 'tableId');
$row = $table->readRow($_GET["key"]);
$end = hrtime(true);
echo (($end - $start)/1000000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment