Skip to content

Instantly share code, notes, and snippets.

@localhots
Last active February 1, 2016 20:53
Show Gist options
  • Save localhots/f29570859370cac5eca3 to your computer and use it in GitHub Desktop.
Save localhots/f29570859370cac5eca3 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"time"
as "github.com/aerospike/aerospike-client-go"
)
func main() {
var populate, test bool
flag.BoolVar(&populate, "p", false, "Populate")
flag.BoolVar(&test, "t", false, "Test")
flag.Parse()
if !populate && !test {
flag.Usage()
return
}
client, err := as.NewClient("127.0.0.1", 3000)
if err != nil {
panic(err)
}
policy := as.NewWritePolicy(0, 0)
key, err := as.NewKey("api", "negatives_test", "test")
if err != nil {
panic(err)
}
llist := client.GetLargeList(policy, key, "mrbin", "")
if err != nil {
panic(err)
}
if populate {
measure("Populate LLIST", func() {
doPopulate(llist)
})
}
if test {
measure("Run tests", func() {
doTest(llist)
})
}
}
func doTest(llist *as.LargeList) {
size, err := llist.Size()
fmt.Printf("Size: %v | Error: %v\n", size, err)
vals, err := llist.FindFirst(10)
fmt.Printf("First 10: %v | Error: %v\n", vals, err)
vals, err = llist.FindLast(10)
fmt.Printf("Last 10: %v | Error: %v\n", vals, err)
vals, err = llist.FindFrom(-1, 10)
fmt.Printf("From -1, 10: %v | Error: %v\n", vals, err)
for i := 1; i <= 10; i++ {
vals, err = llist.FindFrom(-100000*i, 10)
fmt.Printf("From %d, 10: %v | Error: %v\n", -100000*i, vals, err)
}
}
func doPopulate(llist *as.LargeList) {
batch := []interface{}{}
n := 1000 * 1000
for i := -1; i >= -n; i-- {
batch = append(batch, i)
if len(batch) == 100 {
fmt.Println("Processing batch. Items left: ", n+i)
if err := llist.Update(batch...); err != nil {
panic(err)
}
batch = []interface{}{}
}
}
}
func measure(name string, f func()) {
fmt.Printf("%s started\n", name)
start := time.Now()
f()
dur := time.Now().Sub(start)
fmt.Printf("%s finished in %.2fms\n", name, float64(dur)/1000/1000)
}
// Aerospike 3.5.15
// Size: 1000000 | Error: <nil>
// First 10: [-344288 -344287 -344286 -344285 -344284 -344283 -344282 -344281 -344280 -344279] | Error: <nil>
// Last 10: [-1 -2 -3 -4 -5 -6 -7 -8 -9 -10] | Error: <nil>
// From -1, 10: [-1] | Error: <nil>
// From -100000, 10: [-100000 -99999 -99998 -99997 -99996 -99995 -99994 -99993 -99992 -99991] | Error: <nil>
// From -200000, 10: [-826590 -826589 -826588 -826587 -826586 -826585 -826584 -826583 -826582 -826581] | Error: <nil>
// From -300000, 10: [-826590 -826589 -826588 -826587 -826586 -826585 -826584 -826583 -826582 -826581] | Error: <nil>
// From -400000, 10: [-826590 -826589 -826588 -826587 -826586 -826585 -826584 -826583 -826582 -826581] | Error: <nil>
// From -500000, 10: [-1000000 -999999 -999998 -999997 -999996 -999995 -999994 -999993 -999992 -999991] | Error: <nil>
// From -600000, 10: [-1000000 -999999 -999998 -999997 -999996 -999995 -999994 -999993 -999992 -999991] | Error: <nil>
// From -700000, 10: [-667339 -667338 -667337 -667336 -667335 -667334 -667333 -667332 -667331 -667330] | Error: <nil>
// From -800000, 10: [-667339 -667338 -667337 -667336 -667335 -667334 -667333 -667332 -667331 -667330] | Error: <nil>
// From -900000, 10: [-900000 -899999 -899998 -899997 -899996 -899995 -899994 -899993 -899992 -899991] | Error: <nil>
// From -1000000, 10: [-1000000 -999999 -999998 -999997 -999996 -999995 -999994 -999993 -999992 -999991] | Error: <nil>
// Aerospike 3.6.1
// Size: 1000000 | Error: <nil>
// First 10: [-344288 -344287 -344286 -344285 -344284 -344283 -344282 -344281 -344280 -344279] | Error: <nil>
// Last 10: [-1 -2 -3 -4 -5 -6 -7 -8 -9 -10] | Error: <nil>
// From -1, 10: [-1] | Error: <nil>
// From -100000, 10: [-100000 -99999 -99998 -99997 -99996 -99995 -99994 -99993 -99992 -99991] | Error: <nil>
// From -200000, 10: [-826590 -826589 -826588 -826587 -826586 -826585 -826584 -826583 -826582 -826581] | Error: <nil>
// From -300000, 10: [-826590 -826589 -826588 -826587 -826586 -826585 -826584 -826583 -826582 -826581] | Error: <nil>
// From -400000, 10: [-826590 -826589 -826588 -826587 -826586 -826585 -826584 -826583 -826582 -826581] | Error: <nil>
// From -500000, 10: [-1000000 -999999 -999998 -999997 -999996 -999995 -999994 -999993 -999992 -999991] | Error: <nil>
// From -600000, 10: [-1000000 -999999 -999998 -999997 -999996 -999995 -999994 -999993 -999992 -999991] | Error: <nil>
// From -700000, 10: [-667339 -667338 -667337 -667336 -667335 -667334 -667333 -667332 -667331 -667330] | Error: <nil>
// From -800000, 10: [-667339 -667338 -667337 -667336 -667335 -667334 -667333 -667332 -667331 -667330] | Error: <nil>
// From -900000, 10: [-900000 -899999 -899998 -899997 -899996 -899995 -899994 -899993 -899992 -899991] | Error: <nil>
// From -1000000, 10: [-1000000 -999999 -999998 -999997 -999996 -999995 -999994 -999993 -999992 -999991] | Error: <nil>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment