示例#1
0
文件: main.go 项目: abhi-bit/gouch
func main() {

	g, err := gouch.Open("./index.1", os.O_RDONLY)
	if err != nil {
		fmt.Println("Index file open errored")
	} else {
		fmt.Println("Index file open success")
	}
	fmt.Printf("Header count: %d\n", g.GetHeaderCount())
	g.Close()
}
示例#2
0
文件: server.go 项目: vmx/gouch
func runQuery(w http.ResponseWriter, r *http.Request) {
	_, ok := w.(http.Flusher)
	if !ok {
		http.Error(w, "Streaming unsupported", http.StatusInternalServerError)
		return
	}

	w.Header().Set("Connection", "keep-alive")
	w.Header().Set("Cache-Control", "no-cache")

	startKey := ""
	endKey := ""
	var limit int

	params := r.URL.Query()
	if limitParam, ok := params["limit"]; ok && len(limitParam) > 0 {
		limit, _ = strconv.Atoi(limitParam[0])
	}
	if start, ok := params["start"]; ok && len(start) > 0 {
		startKey = start[0]
	}
	if end, ok := params["end"]; ok && len(end) > 0 {
		endKey = end[0]
	}

	context := map[string]int{"count": 0}

	//Chunk in batches
	if limit > 20 {
		c.cacheSize = 20
	} else {
		c.cacheSize = limit
	}
	c.channel = make(chan string, c.cacheSize)

	now := time.Now()
	var g *gouch.Gouch
	if indexFileInfo.GetFDStatus() == false {
		g, _ = gouch.Open("/tmp/1M_pymc_index", os.O_RDONLY)
		indexFileInfo = g.DeepCopy()
		indexFileInfo.SetStatus(true)
	} else {
		g = indexFileInfo.DeepCopy()
	}

	err := indexFileInfo.AllDocsMapReduce(startKey, endKey, allDocumentsCallback, context, w, limit)
	if err != nil {
		fmt.Printf("Failed tree traversal\n")
	}
	//Not closing FD so that we could reuse it
	//indexFileInfo.Close()
	fmt.Fprintf(w, "Time elapsed: %v\n", time.Since(now))
}
示例#3
0
func BenchmarkTraversal(b *testing.B) {
	for i := 0; i < b.N; i++ {
		g, err := gouch.Open("../example/1M_pymc_index", os.O_RDONLY)

		context := map[string]int{"count": 0}
		var w io.Writer
		err = g.AllDocsMapReduce("", "", gouch.DefaultDocumentCallback, context, w, 10)
		if err != nil {
			log.Fatal(err)
		}
	}
}
示例#4
0
文件: debug_test.go 项目: vmx/gouch
func TestDebugHeader(t *testing.T) {
	db, err := gouch.Open(testFileName, os.O_RDONLY)
	if err != nil {
		t.Fatal(err)
	}
	//defer db.Close()

	buffer := new(bytes.Buffer)
	//db.DebugAddress(buffer, 0x39000, true, false, -1)
	//By-id ptr
	db.DebugAddress(buffer, 0x182878, true, false, -1)

	db.DebugAddress(buffer, 3570644, true, false, -1)

	if buffer.String() != expectedHeader {
		t.Errorf("expcted '%s'\n got '%s'\n", expectedHeader, buffer.String())
	}
}
示例#5
0
文件: main.go 项目: vmx/gouch
func main() {
	// godebug
	_ = "breakpoint"
	//res := make(chan int)
	runtime.GOMAXPROCS(8)
	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	var w io.Writer
	//context := map[string]int{"count": 0}

	//g, err := gouch.Open("./index_with_1_entry", os.O_RDONLY)

	//100K records
	g, err := gouch.Open("./abhi_pymc_index", os.O_RDONLY)
	//g, err := gouch.Open("./composite_key_default", os.O_RDONLY)

	//1M records
	//g, err := gouch.Open("1M_pymc_index", os.O_RDONLY)

	if err != nil {
		fmt.Errorf("Crashed while opening file\n")
	}

	defer g.Close()
	//By-Id Btree
	//err = g.AllDocuments("", "", 100, allDocumentsCallback, context, w)
	//err = g.AllDocuments("", "", 100, allDocumentsCallback, context, w)

	//Map-reduce Btree
	/*for i := 0; i < 100; i++ {
		go func(i int) {
			context := map[string]int{"count": 0}
			err = g.AllDocsMapReduce("", "", allDocumentsCallback, context, w, 10)
			res <- i
		}(i)
	}

	for i := 0; i < 100; i++ {
		select {
		case _ = <-res:
			continue
			//fmt.Println(resi)
		}
	}*/

	f, _ := os.Create("mprof")
	pprof.WriteHeapProfile(f)
	f.Close()

	context := map[string]int{"count": 0}
	err = g.AllDocsMapReduce("", "", allDocumentsCallback, context, w, 10)
}