Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

any reason for the following performance inconsistency? #627

Open
evnix opened this issue Dec 2, 2016 · 0 comments
Open

any reason for the following performance inconsistency? #627

evnix opened this issue Dec 2, 2016 · 0 comments

Comments

@evnix
Copy link
Contributor

evnix commented Dec 2, 2016

100,000 iterations and each iteration inserts/deletes 583 bytes.
push took 2.177376983 secs (median)
pop took 15.56463868 secs (median)

500,000 iterations and each iteration inserts/deletes 583 bytes.
push took 148.10161673 secs (median)
pop took 327.692383578 secs (median)

1000,000 iterations and each iteration inserts/deletes 583 bytes.
push took 220.086547771 secs (median)
pop took 2661.85252924 secs (median)

as you can see, 100,000 and 1 million look similar. i.e, the time difference(huge) between inserting x number of elements and deleting x number of elements.

while for 500,000 there is not a big difference. But Why????
is it something related to rebalancing during the deletes but if so why doesn't it show in 500,000 iterations?

Note: the transaction is only committed at the very end. the code is as follows:

num := 500000 //the number of iterations
db, err := bolt.Open("test/testcow.db", 0777, nil)
    if err != nil {
        log.Fatal(err)
    }
    
    defer db.Close()
    
    tx, err2 := db.Begin(true)
    if err2 != nil {
        log.Fatal(err2)
    }
    defer tx.Rollback()

    // Use the transaction...
    b, err3 := tx.CreateBucket([]byte("MyBucket"))

    if err3 != nil {
        log.Fatal(err2)
    }

       //this loop runs the num iterations 20 times for calculating avg.
	for m := 0; m < 20; m++ {

		start := time.Now()
		elapsed := time.Since(start)

		for i = 0; i < num; i++ {
		
		
		    if(i%10000==0){
		    
		    
		            elapsed = time.Since(start)
		            log.Printf("%d process at .. %f", i,elapsed.Seconds())
		    }


                    b.Put([]byte(strconv.FormatInt(i,10)), []byte(workload))

		}


		log.Printf("%d push took %s", m,elapsed)
        fmt.Println("push took ", elapsed.Seconds())

		runtime.GC()
		debug.FreeOSMemory()
		time.Sleep(1 * time.Second)

		start = time.Now()

		for i = 0; i < num; i++ {
		
		    if(i%1000==0){
		    
		            elapsed = time.Since(start)
		            log.Printf("%d process at ... %f", i,elapsed.Seconds())
		    }

			b.Delete([]byte(strconv.FormatInt(i,10)))

		}

		elapsed = time.Since(start)
		log.Printf("pop took %s", elapsed)
		fmt.Println("pop took ", elapsed.Seconds())
		runtime.GC()
		debug.FreeOSMemory()
		time.Sleep(1 * time.Second)

	}
	
	    if err9 := tx.Commit(); err9 != nil {
        log.Fatal(err9)
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant