Skip to content

Commit

Permalink
perf: add load test for active orders (#472)
Browse files Browse the repository at this point in the history
* fix: active orders overflow bug

* chore: active orders observability TODOs

* updates

* lint

* add concurrency to the order book processing in active orders

* active order fault tolerance

* perf: add load test for active orders

* add godocs

---------

Co-authored-by: Deividas Petraitis <[email protected]>
  • Loading branch information
p0mvn and deividaspetraitis authored Aug 27, 2024
1 parent bc570d6 commit e6d44b6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
17 changes: 2 additions & 15 deletions locust/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,5 @@
from token_prices import TokenPrices
from in_given_out import ExactAmountOutQuote
from out_given_in import ExactAmountInQuote
import random

# random addresses with balances
addr1 = "osmo1044qatzg4a0wm63jchrfdnn2u8nwdgxxt6e524"
addr2 = "osmo1aaa9rpq2m6tu6t0dvknqq2ps7zudxv7th209q4"
addr3 = "osmo18sd2ujv24ual9c9pshtxys6j8knh6xaek9z83t"
addr4 = "osmo140p7pef5hlkewuuramngaf5j6s8dlynth5zm06"

addresses = [addr1, addr2, addr3, addr4]

class SQS(HttpUser):
@task
def passthroughTotalCoins(self):
random_address = random.choice(addresses)
self.client.get(f"/passthrough/portfolio-assets/{random_address}")
from orderbook_active_orders import OrderbookActiveOrders
from passthrough_portfolio_balances import PassthroughPortfolioBalances
18 changes: 18 additions & 0 deletions locust/orderbook_active_orders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from locust import HttpUser, task
from pairs import *

fill_bot_address = "osmo10s3vlv40h64qs2p98yal9w0tpm4r30uyg6ceux"

class OrderbookActiveOrders(HttpUser):
# on_start is called when a Locust start before any task is scheduled.
def on_start(self):
pass

# on_stop is called when the TaskSet is stopping
def on_stop(self):
pass


@task
def quoteUOSMOUSDC_1In(self):
self.client.get(f"passthrough/active-orders?userOsmoAddress={fill_bot_address}")
17 changes: 17 additions & 0 deletions locust/passthrough_portfolio_balances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from locust import HttpUser, task
from pairs import *
import random

# random addresses with balances
addr1 = "osmo1044qatzg4a0wm63jchrfdnn2u8nwdgxxt6e524"
addr2 = "osmo1aaa9rpq2m6tu6t0dvknqq2ps7zudxv7th209q4"
addr3 = "osmo18sd2ujv24ual9c9pshtxys6j8knh6xaek9z83t"
addr4 = "osmo140p7pef5hlkewuuramngaf5j6s8dlynth5zm06"

addresses = [addr1, addr2, addr3, addr4]

class PassthroughPortfolioBalances(HttpUser):
@task
def passthroughTotalCoins(self):
random_address = random.choice(addresses)
self.client.get(f"/passthrough/portfolio-assets/{random_address}")
21 changes: 17 additions & 4 deletions orderbook/usecase/orderbook_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ type orderbookUseCaseImpl struct {

var _ mvc.OrderBookUsecase = &orderbookUseCaseImpl{}

const (
// Max number of ticks to query at a time
maxQueryTicks = 500
// Max number of ticks cancels to query at a time
maxQueryTicksCancels = 100
)

// New creates a new orderbook use case.
func New(
orderbookRepository orderbookdomain.OrderBookRepository,
Expand Down Expand Up @@ -386,8 +393,11 @@ func (o *orderbookUseCaseImpl) createFormattedLimitOrder(
}, nil
}

const maxQueryTicks = 500

// fetchTicksForOrderbook fetches the ticks for a given tick ID and contract address.
// It returns the ticks and an error if any.
// Errors if:
// - failed to fetch ticks
// - mismatch in number of ticks fetched
func (o *orderbookUseCaseImpl) fetchTicksForOrderbook(ctx context.Context, contractAddress string, tickIDs []int64) ([]orderbookdomain.Tick, error) {
finalTickStates := make([]orderbookdomain.Tick, 0, len(tickIDs))

Expand All @@ -414,8 +424,11 @@ func (o *orderbookUseCaseImpl) fetchTicksForOrderbook(ctx context.Context, contr
return finalTickStates, nil
}

const maxQueryTicksCancels = 100

// fetchTickUnrealizedCancels fetches the unrealized cancels for a given tick ID and contract address.
// It returns the unrealized cancels and an error if any.
// Errors if:
// - failed to fetch unrealized cancels
// - mismatch in number of unrealized cancels fetched
func (o *orderbookUseCaseImpl) fetchTickUnrealizedCancels(ctx context.Context, contractAddress string, tickIDs []int64) ([]orderbookgrpcclientdomain.UnrealizedTickCancels, error) {
allUnrealizedCancels := make([]orderbookgrpcclientdomain.UnrealizedTickCancels, 0, len(tickIDs))

Expand Down

0 comments on commit e6d44b6

Please sign in to comment.