forked from dtm-labs/dtm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dtm-labs#195 from dtm-labs/alpha
flash sales bench ok
- Loading branch information
Showing
50 changed files
with
826 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
run: | ||
deadline: 5m | ||
skip-dirs: | ||
- test | ||
# - test | ||
# - bench | ||
|
||
linter-settings: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# !/bin/bash | ||
|
||
set -x | ||
|
||
export LOG_LEVEL=fatal | ||
export STORE_DRIVER=redis | ||
export STORE_HOST=localhost | ||
export STORE_PORT=6379 | ||
export BUSI_REDIS=localhost:6379 | ||
./bench redis & | ||
echo 'sleeping 3s for dtm bench to run up.' && sleep 3 | ||
curl "http://127.0.0.1:8083/api/busi_bench/benchFlashSalesReset" | ||
ab -n 300000 -c 20 "http://127.0.0.1:8083/api/busi_bench/benchFlashSales" | ||
pkill bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package dtmcli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dtm-labs/dtm/dtmcli/logger" | ||
"github.com/go-redis/redis/v8" | ||
) | ||
|
||
// RedisCheckAdjustAmount check the value of key is valid and >= amount. then adjust the amount | ||
func (bb *BranchBarrier) RedisCheckAdjustAmount(rd *redis.Client, key string, amount int, barrierExpire int) error { | ||
bb.BarrierID = bb.BarrierID + 1 | ||
bkey1 := fmt.Sprintf("%s-%s-%s-%02d", bb.Gid, bb.BranchID, bb.Op, bb.BarrierID) | ||
originOp := map[string]string{ | ||
BranchCancel: BranchTry, | ||
BranchCompensate: BranchAction, | ||
}[bb.Op] | ||
bkey2 := fmt.Sprintf("%s-%s-%s-%02d", bb.Gid, bb.BranchID, originOp, bb.BarrierID) | ||
v, err := rd.Eval(rd.Context(), ` -- RedisCheckAdjustAmount | ||
local v = redis.call('GET', KEYS[1]) | ||
local e1 = redis.call('GET', KEYS[2]) | ||
if v == false or v + ARGV[1] < 0 then | ||
return 'FAILURE' | ||
end | ||
if e1 ~= false then | ||
return | ||
end | ||
redis.call('SET', KEYS[2], 'op', 'EX', ARGV[3]) | ||
if ARGV[2] ~= '' then | ||
local e2 = redis.call('GET', KEYS[3]) | ||
if e2 == false then | ||
redis.call('SET', KEYS[3], 'rollback', 'EX', ARGV[3]) | ||
return | ||
end | ||
end | ||
redis.call('INCRBY', KEYS[1], ARGV[1]) | ||
`, []string{key, bkey1, bkey2}, amount, originOp, barrierExpire).Result() | ||
logger.Debugf("lua return v: %v err: %v", v, err) | ||
if err == redis.Nil { | ||
err = nil | ||
} | ||
if err == nil && v == ResultFailure { | ||
err = ErrFailure | ||
} | ||
return err | ||
} | ||
|
||
// RedisQueryPrepared query prepared for redis | ||
func (bb *BranchBarrier) RedisQueryPrepared(rd *redis.Client, barrierExpire int) error { | ||
bkey1 := fmt.Sprintf("%s-%s-%s-%s", bb.Gid, "00", "msg", "01") | ||
v, err := rd.Eval(rd.Context(), ` -- RedisQueryPrepared | ||
local v = redis.call('GET', KEYS[1]) | ||
if v == false then | ||
redis.call('SET', KEYS[1], 'rollback', 'EX', ARGV[1]) | ||
v = 'rollback' | ||
end | ||
if v == 'rollback' then | ||
return 'FAILURE' | ||
end | ||
`, []string{bkey1}, barrierExpire).Result() | ||
logger.Debugf("lua return v: %v err: %v", v, err) | ||
if err == redis.Nil { | ||
err = nil | ||
} | ||
if err == nil && v == ResultFailure { | ||
err = ErrFailure | ||
} | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.