-
-
Save walf443/498de51af5f09b08f20666b0e872aa76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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