Skip to content

Instantly share code, notes, and snippets.

@khaf
Created December 16, 2014 16:27
Show Gist options
  • Save khaf/50809b45ba5645f9f80c to your computer and use it in GitHub Desktop.
Save khaf/50809b45ba5645f9f80c to your computer and use it in GitHub Desktop.

Revisions

  1. khaf created this gist Dec 16, 2014.
    75 changes: 75 additions & 0 deletions gistfile1.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    package main

    import (
    "log"
    "math"
    "runtime"
    "time"

    as "github.com/aerospike/aerospike-client-go"
    )

    const (
    HOSTNAME = "127.0.0.1"
    PORT = 3000
    NAMESPACE = "test"
    SET = ""
    )

    func panicOnError(err error) {
    if err != nil {
    log.Fatalln(err)
    }
    }

    func main() {
    runtime.GOMAXPROCS(runtime.NumCPU())

    client, err := as.NewClient(HOSTNAME, PORT)
    panicOnError(err)

    count := 0
    for i := 1; i < math.MaxInt16; i *= 2 {
    for j := count; j < i; j++ {
    key, _ := as.NewKey(NAMESPACE, SET, j)
    err := client.PutBins(nil, key, as.NewBin("bin", j))
    panicOnError(err)
    count++
    }

    log.Printf("There are now %d records in the database...\n", i)

    for j := 0; j < 3; j++ {
    t := time.Now()
    scan(client, i)
    log.Printf("Scanning %d records took: %v\n", i, time.Now().Sub(t))
    }

    }
    }

    // scans the database and checks if the number of returned records
    // is the same as the expected number
    func scan(client *as.Client, expectedRecordsCount int) {
    recordset, err := client.ScanAll(nil, NAMESPACE, SET)
    panicOnError(err)
    count := 0

    L:
    for {
    select {
    case rec := <-recordset.Records:
    if rec == nil {
    break L
    }
    count++
    case err := <-recordset.Errors:
    panicOnError(err)
    }
    }

    log.Println("Number of records returned by ScanAll:", count)
    if expectedRecordsCount != count {
    log.Fatalf("Expected ScanAll to return %d records, but it returned %d.\n", expectedRecordsCount, count)
    }
    }