mirror of
https://github.com/simon987/imhashdb.git
synced 2025-12-17 00:09:05 +00:00
cleanup
This commit is contained in:
29
web/api.go
29
web/api.go
@@ -1,16 +1,12 @@
|
||||
package main
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-redis/redis/v7"
|
||||
"github.com/mailru/easyjson"
|
||||
. "github.com/simon987/imhashdb"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -112,28 +108,15 @@ func hash(c *gin.Context) {
|
||||
c.Data(200, gin.MIMEJSON, b)
|
||||
}
|
||||
|
||||
func main() {
|
||||
Init()
|
||||
|
||||
f, err := os.Create("prof")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
go func() {
|
||||
time.Sleep(time.Second * 15)
|
||||
pprof.StopCPUProfile()
|
||||
fmt.Println("!!!!!!!!!!!!!!!")
|
||||
f.Close()
|
||||
}()
|
||||
|
||||
func Main() error {
|
||||
r := gin.Default()
|
||||
r.Use(CORSMiddleware())
|
||||
r.POST("/api/hash", hash)
|
||||
r.POST("/api/query", query)
|
||||
|
||||
//TODO: concurrency
|
||||
go queryWorker()
|
||||
for i := 0; i < Conf.QueryConcurrency; i++ {
|
||||
go queryWorker()
|
||||
}
|
||||
|
||||
r.Run()
|
||||
return r.Run(Conf.ApiAddr)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -17,7 +17,7 @@ const CacheLength = time.Second * 30
|
||||
func queryWorker() {
|
||||
Logger.Info("Query worker started")
|
||||
for {
|
||||
value := Rdb.BZPopMin(time.Second * 30, inQueue).Val()
|
||||
value := Rdb.BZPopMin(time.Second*30, inQueue).Val()
|
||||
if value == nil {
|
||||
continue
|
||||
}
|
||||
@@ -38,13 +38,13 @@ func queryWorker() {
|
||||
Logger.Info("worker query done")
|
||||
b = resp
|
||||
}
|
||||
Rdb.Set(outQueue + member, b, CacheLength)
|
||||
Rdb.Set(outQueue+member, b, CacheLength)
|
||||
}
|
||||
}
|
||||
|
||||
func dbQuery(req QueryReq, value string) ([]byte, error) {
|
||||
Rdb.SAdd(wipQueue, value)
|
||||
Rdb.Expire(wipQueue, time.Minute * 10)
|
||||
Rdb.Expire(wipQueue, time.Minute*10)
|
||||
|
||||
defer Rdb.SRem(wipQueue, value)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user