Skip to content

Commit 192581a

Browse files
Merge pull request RediSearch#11 from filipecosta90/go.mod
Revamped project. Enabled go modules. Checking format.
2 parents f2ceca7 + 5e23f3c commit 192581a

File tree

10 files changed

+135
-46
lines changed

10 files changed

+135
-46
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
*.a
22
*.o
33
RediSearchBenchmark
4+
bin/*
5+
*.csv
6+
*.xml
7+
*.gz
8+
.idea/*

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Go parameters
2+
GOCMD=GO111MODULE=on go
3+
GOBUILD=$(GOCMD) build
4+
GOINSTALL=$(GOCMD) install
5+
GOCLEAN=$(GOCMD) clean
6+
GOTEST=$(GOCMD) test
7+
GOGET=$(GOCMD) get -v
8+
GOMOD=$(GOCMD) mod
9+
GOFMT=$(GOCMD) fmt
10+
11+
# Build time variables
12+
ifeq ($(GIT_SHA),)
13+
GIT_SHA:=$(shell git rev-parse HEAD)
14+
endif
15+
16+
ifeq ($(GIT_DIRTY),)
17+
GIT_DIRTY:=$(shell git diff --no-ext-diff 2> /dev/null | wc -l)
18+
endif
19+
20+
.PHONY: all
21+
22+
all: get RediSearchBenchmark
23+
fmt:
24+
$(GOFMT) ./...
25+
26+
27+
checkfmt:
28+
@echo 'Checking gofmt';\
29+
bash -c "diff -u <(echo -n) <(gofmt -d .)";\
30+
EXIT_CODE=$$?;\
31+
if [ "$$EXIT_CODE" -ne 0 ]; then \
32+
echo '$@: Go files must be formatted with gofmt'; \
33+
fi && \
34+
exit $$EXIT_CODE
35+
36+
get:
37+
$(GOGET) -t -v ./...
38+
39+
test: get fmt
40+
$(GOTEST) -v -race -coverprofile=coverage.txt -covermode=atomic ./...
41+
42+
RediSearchBenchmark: $(wildcard ./index/*.go) $(wildcard ./ingest/*.go) $(wildcard ./query/*.go) $(wildcard ./synth/*.go)
43+
$(GOBUILD) -o ./bin/$@ -ldflags="-X 'main.GitSHA1=$(GIT_SHA)' -X 'main.GitDirty=$(GIT_DIRTY)'" .

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
[![GoDoc](https://godoc.org/github.com/RediSearch/RediSearchBenchmark?status.svg)](https://godoc.org/github.com/RediSearch/RediSearchBenchmark)
44

55
# RediSearchBenchmarks
6-
This is a Go application (originally written by Dvir Volk) which supports reading, indexing and searching in [Wikipedia Abstract Data Dumps](https://s3.amazonaws.com/uploads-files/wiki_dump.gz) using two search engines:
6+
This is a Go application (originally written by Dvir Volk) which supports reading, indexing and searching using two search engines:
77

8-
* [RediSearch](https://github.com/RedisLabsModules/RediSearch)
8+
* [RediSearch](https://github.com/RediSearch/RediSearch)
99
* [Elasticsearch](https://www.elastic.co/)
1010

11+
with the following datasets:
12+
13+
* [Wikipedia Abstract Data Dumps](https://s3.amazonaws.com/benchmarks.redislabs/redisearch/datasets/enwiki-abstract/enwiki-latest-abstract.xml): from English-language Wikipedia:Database page abstracts. This use case generates 3 TEXT fields per document.
14+
* [pmc](https://s3.amazonaws.com/benchmarks.redislabs/redisearch/datasets/pmc/documents.json): Full text benchmark with academic papers from PMC.
15+
1116
## Usage
1217

1318
```

go.mod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module github.com/RediSearch/RediSearchBenchmark
2+
3+
go 1.16
4+
5+
require (
6+
github.com/garyburd/redigo v1.6.2
7+
github.com/mailru/easyjson v0.7.7 // indirect
8+
github.com/olivere/elastic v6.2.35+incompatible // indirect
9+
github.com/pkg/errors v0.9.1 // indirect
10+
github.com/stretchr/testify v1.7.0
11+
github.com/vanng822/go-solr v0.10.0
12+
gopkg.in/olivere/elastic.v6 v6.2.35
13+
)

go.sum

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/garyburd/redigo v1.6.2 h1:yE/pwKCrbLpLpQICzYTeZ7JsTA/C53wFTJHaEtRqniM=
4+
github.com/garyburd/redigo v1.6.2/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
5+
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
6+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
7+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
8+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
9+
github.com/olivere/elastic v6.2.35+incompatible h1:MMklYDy2ySi01s123CB2WLBuDMzFX4qhFcA5tKWJPgM=
10+
github.com/olivere/elastic v6.2.35+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
11+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
12+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
16+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
17+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18+
github.com/vanng822/go-solr v0.10.0 h1:oygAxyFL2apSN8vddxDXoyho40z66Guu9nwH7ANr6wM=
19+
github.com/vanng822/go-solr v0.10.0/go.mod h1:FSglzTPzoNVKTXP+SqEQiiz284cKzcKpeRXmwPa81wc=
20+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
21+
gopkg.in/olivere/elastic.v6 v6.2.35 h1:/5dJ0UzM231DGl9eDYOdDgv8yCFzAHQVPMo69rnylks=
22+
gopkg.in/olivere/elastic.v6 v6.2.35/go.mod h1:2cTT8Z+/LcArSWpCgvZqBgt3VOqXiy7v00w12Lz8bd4=
23+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
24+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

index/elastic/elastic.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import (
66
"net/http"
77
"time"
88

9+
"context"
910
"github.com/RediSearch/RediSearchBenchmark/index"
1011
"github.com/RediSearch/RediSearchBenchmark/query"
1112
"gopkg.in/olivere/elastic.v6"
12-
"context"
1313
)
1414

1515
// Index is an ElasticSearch index
1616
type Index struct {
1717
conn *elastic.Client
1818

19-
md *index.Metadata
20-
name string
21-
typ string
19+
md *index.Metadata
20+
name string
21+
typ string
2222
disableCache bool
2323
}
2424

@@ -27,7 +27,7 @@ var conn *elastic.Client = nil
2727
// NewIndex creates a new elasticSearch index with the given address and name. typ is the entity type
2828
func NewIndex(addr, name, typ string, disableCache bool, md *index.Metadata) (*Index, error) {
2929
var err error
30-
if conn == nil{
30+
if conn == nil {
3131
client := &http.Client{
3232
Transport: &http.Transport{
3333
MaxIdleConnsPerHost: 200,
@@ -39,12 +39,12 @@ func NewIndex(addr, name, typ string, disableCache bool, md *index.Metadata) (*I
3939
return nil, err
4040
}
4141
}
42-
42+
4343
ret := &Index{
44-
conn: conn,
45-
md: md,
46-
name: name,
47-
typ: typ,
44+
conn: conn,
45+
md: md,
46+
name: name,
47+
typ: typ,
4848
disableCache: disableCache,
4949
}
5050

@@ -95,10 +95,10 @@ func (i *Index) Create() error {
9595
// "payloads": true,
9696
// },
9797
// },
98-
// }
98+
// }
9999

100100
mappings := map[string]mapping{
101-
i.typ: doc,
101+
i.typ: doc,
102102
// "autocomplete": ac,
103103
}
104104

@@ -127,7 +127,7 @@ func (i *Index) Index(docs []index.Document, opts interface{}) error {
127127
}
128128
_, err := blk.Refresh("true").Do(context.Background())
129129

130-
if err != nil{
130+
if err != nil {
131131
panic(err)
132132
}
133133

index/redisearch/index.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type IndexingOptions struct {
3636

3737
type ConnectionPool struct {
3838
sync.Mutex
39-
pools map[string]*redis.Pool
39+
pools map[string]*redis.Pool
4040
}
4141

4242
var connectionPool = ConnectionPool{
@@ -48,7 +48,7 @@ type Index struct {
4848
sync.Mutex
4949
hosts []string
5050
password string
51-
temporary int
51+
temporary int
5252
md *index.Metadata
5353
name string
5454
commandPrefix string
@@ -64,12 +64,12 @@ func (i *Index) getConn() redis.Conn {
6464
if !found {
6565
pool = redis.NewPool(func() (redis.Conn, error) {
6666
// TODO: Add timeouts. and 2 separate pools for indexing and querying, with different timeouts
67-
if i.password != ""{
68-
return redis.Dial("tcp", host, redis.DialPassword(i.password))
69-
}else{
70-
return redis.Dial("tcp", host)
67+
if i.password != "" {
68+
return redis.Dial("tcp", host, redis.DialPassword(i.password))
69+
} else {
70+
return redis.Dial("tcp", host)
7171
}
72-
72+
7373
}, maxConns)
7474
pool.TestOnBorrow = func(c redis.Conn, t time.Time) error {
7575
if time.Since(t).Seconds() > 3 {
@@ -92,8 +92,8 @@ func NewIndex(addrs []string, pass string, temporary int, name string, md *index
9292

9393
hosts: addrs,
9494

95-
md: md,
96-
password: pass,
95+
md: md,
96+
password: pass,
9797
temporary: temporary,
9898

9999
name: name,
@@ -121,7 +121,7 @@ func (i *Index) GetName() string {
121121
func (i *Index) Create() error {
122122

123123
args := redis.Args{i.name}
124-
if i.temporary != -1{
124+
if i.temporary != -1 {
125125
t := strconv.Itoa(i.temporary)
126126
args = append(args, "TEMPORARY", t)
127127
}

ingest/ingest.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,16 @@ func ReadFile(fileName string, r DocumentReader, idx index.Index, ac index.Autoc
190190
for doc := range doch {
191191
if doc.Id != "" {
192192
docs = append(docs, doc)
193-
numOfDocs++;
194-
}else{
193+
numOfDocs++
194+
} else {
195195
fmt.Println("warning empty id")
196196
}
197-
if(len(docs) > 1000){
197+
if len(docs) > 1000 {
198198
idx.Index(docs, opts)
199199
docs = []index.Document{}
200200
}
201201
}
202-
if(len(docs) > 0){
202+
if len(docs) > 0 {
203203
idx.Index(docs, opts)
204204
}
205205
}(doch)

ingest/wikipedia_abstract.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (r *WikipediaAbstractsReader) LoadScores(fileName string) error {
8686
return nil
8787
}
8888

89-
func (wr *WikipediaAbstractsReader) Read(r io.Reader, ch chan index.Document, maxDocsToRead int, idx index.Index) error {
89+
func (wr *WikipediaAbstractsReader) Read(r io.Reader, ch chan index.Document, maxDocsToRead int, idx index.Index) error {
9090

9191
dec := xml.NewDecoder(r)
9292
go func() {
@@ -129,9 +129,9 @@ func (wr *WikipediaAbstractsReader) Read(r io.Reader, ch chan index.Document, ma
129129
}
130130
currentText = ""
131131
}
132-
if maxDocsToRead != -1 && docsRead >= maxDocsToRead{
132+
if maxDocsToRead != -1 && docsRead >= maxDocsToRead {
133133
break
134-
}
134+
}
135135
tok, err = dec.RawToken()
136136

137137
}

main.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import (
44
"flag"
55
"fmt"
66
"os"
7+
"strconv"
78
"strings"
89
"time"
9-
"strconv"
1010

1111
"runtime"
1212

1313
"sync"
1414

15-
1615
"github.com/RediSearch/RediSearchBenchmark/index"
1716
"github.com/RediSearch/RediSearchBenchmark/index/elastic"
1817
"github.com/RediSearch/RediSearchBenchmark/index/redisearch"
@@ -67,16 +66,16 @@ func main() {
6766

6867
//scoreFile := flag.String("scores", "", "read scores of documents CSV for indexing")
6968
engine := flag.String("engine", "redis", "The search backend to run")
70-
benchmark := flag.String("benchmark", "", "[search|suggest] - if set, we run the given benchmark")
69+
benchmark := flag.String("benchmark", "", "[search|suggest|wildcard|prefix] - if set, we run the given benchmark")
7170
random := flag.Int("random", 0, "Generate random documents with terms like term0..term{N}")
7271
indexesAmount := flag.Int("indexes", 1, "number of indexes to generate")
7372
// fuzzy := flag.Bool("fuzzy", false, "For redis only - benchmark fuzzy auto suggest")
7473
disableCache := flag.Bool("disableCache", false, "for elastic only, disabling query cache")
75-
seconds := flag.Int("duration", 5, "number of seconds to run the benchmark")
74+
seconds := flag.Int("duration", 60, "number of seconds to run the benchmark")
7675
temporary := flag.Int("temporary", -1, "for redisearch only, create a temporary index that will expire after the given amount of seconds, -1 mean no temporary")
7776
conc := flag.Int("c", 4, "benchmark concurrency")
7877
maxDocPerIndex := flag.Int("maxdocs", -1, "specify the numebr of max docs per index, -1 for no limit")
79-
qs := flag.String("queries", "hello world", "comma separated list of queries to benchmark")
78+
qs := flag.String("queries", "barack obama", "comma separated list of queries to benchmark. Use this option only for the historical reasons via `-queries='barack obama'`. If you don't specify a value it will read the input file and randomize the input search terms")
8079
outfile := flag.String("o", "benchmark.csv", "results output file. set to - for stdout")
8180
cmdPrefix := flag.String("prefix", "FT", "Command prefix for FT module")
8281
password := flag.String("password", "", "redis database password")
@@ -91,7 +90,7 @@ func main() {
9190

9291
indexes := make([]index.Index, *indexesAmount)
9392
var opts interface{}
94-
if *engine == "redis"{
93+
if *engine == "redis" {
9594
opts = query.QueryVerbatim
9695
}
9796
// select index to run
@@ -103,7 +102,7 @@ func main() {
103102

104103
// Search benchmark
105104
if *benchmark == "search" {
106-
if(*indexesAmount > 1){
105+
if *indexesAmount > 1 {
107106
panic("search not supported on multiple indexes!!!")
108107
}
109108
name := fmt.Sprintf("search: %s", *qs)
@@ -122,7 +121,7 @@ func main() {
122121
if *random > 0 {
123122
indexes[0].Drop()
124123
err := indexes[0].Create()
125-
if err != nil{
124+
if err != nil {
126125
panic(err)
127126
}
128127

@@ -132,7 +131,7 @@ func main() {
132131
n := 0
133132
ch := make(chan index.Document, N)
134133
go func() {
135-
for i :=0 ; i < *maxDocPerIndex || *maxDocPerIndex == -1 ; i++{
134+
for i := 0; i < *maxDocPerIndex || *maxDocPerIndex == -1; i++ {
136135
ch <- gen.Generate(0)
137136
}
138137
}()
@@ -153,14 +152,14 @@ func main() {
153152

154153
var wg sync.WaitGroup
155154
idxChan := make(chan index.Index, 1)
156-
for i := 0 ; i < 30 ; i++{
155+
for i := 0; i < 30; i++ {
157156
wg.Add(1)
158-
go func(idxChan chan index.Index){
157+
go func(idxChan chan index.Index) {
159158
defer wg.Done()
160-
for idx := range idxChan{
159+
for idx := range idxChan {
161160
idx.Drop()
162161
err := idx.Create()
163-
if err != nil{
162+
if err != nil {
164163
panic(err)
165164
}
166165
wr := &ingest.WikipediaAbstractsReader{}
@@ -179,7 +178,7 @@ func main() {
179178
}(idxChan)
180179
}
181180

182-
for _,idx := range indexes{
181+
for _, idx := range indexes {
183182
idxChan <- idx
184183
}
185184
close(idxChan)

0 commit comments

Comments
 (0)