Skip to content

Commit

Permalink
performance tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Sep 16, 2018
1 parent 41af9a8 commit 0413683
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 152 deletions.
49 changes: 30 additions & 19 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package api
import (
"github.com/MinterTeam/minter-go-node/config"
"github.com/MinterTeam/minter-go-node/eventsdb"
"io"
"io/ioutil"
"log"
"net/http"

Expand Down Expand Up @@ -37,25 +39,25 @@ func RunApi(b *minter.Blockchain, node *node.Node) {

router := mux.NewRouter().StrictSlash(true)

router.HandleFunc("/api/bipVolume", GetBipVolume).Methods("GET")
router.HandleFunc("/api/candidates", GetCandidates).Methods("GET")
router.HandleFunc("/api/candidate/{pubkey}", GetCandidate).Methods("GET")
router.HandleFunc("/api/validators", GetValidators).Methods("GET")
router.HandleFunc("/api/balance/{address}", GetBalance).Methods("GET")
router.HandleFunc("/api/balanceWS", GetBalanceWatcher)
router.HandleFunc("/api/transactionCount/{address}", GetTransactionCount).Methods("GET")
router.HandleFunc("/api/sendTransaction", SendTransaction).Methods("POST")
router.HandleFunc("/api/sendTransactionSync", SendTransactionSync).Methods("POST")
router.HandleFunc("/api/sendTransactionAsync", SendTransactionAsync).Methods("POST")
router.HandleFunc("/api/transaction/{hash}", Transaction).Methods("GET")
router.HandleFunc("/api/block/{height}", Block).Methods("GET")
router.HandleFunc("/api/transactions", Transactions).Methods("GET")
router.HandleFunc("/api/status", Status).Methods("GET")
router.HandleFunc("/api/net_info", NetInfo).Methods("GET")
router.HandleFunc("/api/coinInfo/{symbol}", GetCoinInfo).Methods("GET")
router.HandleFunc("/api/estimateCoinSell", EstimateCoinSell).Methods("GET")
router.HandleFunc("/api/estimateCoinBuy", EstimateCoinBuy).Methods("GET")
router.HandleFunc("/api/estimateTxCommission", EstimateTxCommission).Methods("GET")
router.HandleFunc("/api/bipVolume", wrapper(GetBipVolume)).Methods("GET")
router.HandleFunc("/api/candidates", wrapper(GetCandidates)).Methods("GET")
router.HandleFunc("/api/candidate/{pubkey}", wrapper(GetCandidate)).Methods("GET")
router.HandleFunc("/api/validators", wrapper(GetValidators)).Methods("GET")
router.HandleFunc("/api/balance/{address}", wrapper(GetBalance)).Methods("GET")
router.HandleFunc("/api/balanceWS", wrapper(GetBalanceWatcher))
router.HandleFunc("/api/transactionCount/{address}", wrapper(GetTransactionCount)).Methods("GET")
router.HandleFunc("/api/sendTransaction", wrapper(SendTransaction)).Methods("POST")
router.HandleFunc("/api/sendTransactionSync", wrapper(SendTransactionSync)).Methods("POST")
router.HandleFunc("/api/sendTransactionAsync", wrapper(SendTransactionAsync)).Methods("POST")
router.HandleFunc("/api/transaction/{hash}", wrapper(Transaction)).Methods("GET")
router.HandleFunc("/api/block/{height}", wrapper(Block)).Methods("GET")
router.HandleFunc("/api/transactions", wrapper(Transactions)).Methods("GET")
router.HandleFunc("/api/status", wrapper(Status)).Methods("GET")
router.HandleFunc("/api/net_info", wrapper(NetInfo)).Methods("GET")
router.HandleFunc("/api/coinInfo/{symbol}", wrapper(GetCoinInfo)).Methods("GET")
router.HandleFunc("/api/estimateCoinSell", wrapper(EstimateCoinSell)).Methods("GET")
router.HandleFunc("/api/estimateCoinBuy", wrapper(EstimateCoinBuy)).Methods("GET")
router.HandleFunc("/api/estimateTxCommission", wrapper(EstimateTxCommission)).Methods("GET")

c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
Expand All @@ -71,6 +73,15 @@ func RunApi(b *minter.Blockchain, node *node.Node) {
log.Fatal(http.ListenAndServe(config.GetConfig().APIListenAddress, handler))
}

func wrapper(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
defer io.Copy(ioutil.Discard, r.Body)
defer r.Body.Close()

f(w, r)
}
}

func waitForTendermint() {
for {
_, err := client.Health()
Expand Down
2 changes: 1 addition & 1 deletion core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var (

func NewMinterBlockchain() *Blockchain {

db, err := mintdb.NewLDBDatabase(utils.GetMinterHome()+"/data", 1000, 1000)
db, err := mintdb.NewLDBDatabase(utils.GetMinterHome()+"/data", 1024, 512)

if err != nil {
panic(err)
Expand Down
8 changes: 6 additions & 2 deletions eventsdb/eventsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ func init() {
}

func GetCurrent() *EventsDB {

if edb == nil {
eventsDB, err := mintdb.NewLDBDatabase(utils.GetMinterHome()+"/events", 1000, 1000)
eventsDB, err := mintdb.NewLDBDatabase(utils.GetMinterHome()+"/events", 128, 128)

if err != nil {
panic(err)
Expand Down Expand Up @@ -58,6 +57,11 @@ func (db *EventsDB) AddEvent(height int64, event Event) {
}

func (db *EventsDB) FlushEvents(height int64) error {

if !eventsEnabled {
return nil
}

events := db.GetEvents(height)

key := getKeyForHeight(height)
Expand Down
130 changes: 0 additions & 130 deletions mintdb/memory_database.go

This file was deleted.

0 comments on commit 0413683

Please sign in to comment.