Skip to content

Commit

Permalink
Merge pull request #304 from yunkon-kim/update-perf-eval-client
Browse files Browse the repository at this point in the history
Update a client for performance evaluation
  • Loading branch information
yunkon-kim authored May 17, 2022
2 parents bfd6efa + aca525e commit a77a37d
Showing 1 changed file with 54 additions and 23 deletions.
77 changes: 54 additions & 23 deletions poc-cb-net/cmd/test-client/perf-eval-client/perf-eval-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ var mcisID = "yk01perf"
var config model.Config
var endpointNetworkService string
var endpointEtcd []string
var timeoutToCheckMCIS time.Duration = 150 * time.Second
var durationToCheckMCIS time.Duration = 15 * time.Second

// For this test
var trialNo int
var testCase string
var deadline time.Time = time.Now().Add(24 * time.Hour)
var timeout time.Duration = 1 * time.Hour
var duration time.Duration = 30 * time.Minute
var trialNo int = 0
var testCase string = "1"
var ruleType string
var cmdType string

Expand Down Expand Up @@ -135,8 +140,6 @@ func init() {

endpointNetworkService = config.Service.Endpoint
endpointEtcd = config.ETCD.Endpoints
trialNo = 0
testCase = "1"

fmt.Println("End......... init() of admin-web.go")
fmt.Println("")
Expand All @@ -161,8 +164,10 @@ func main() {
os.Interrupt, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGHUP, syscall.SIGABRT)
defer stop()

d := time.Now().Add(4 * time.Hour)
ctx, cancel := context.WithDeadline(context.Background(), d)
// ctx, cancel := context.WithDeadline(context.TODO(), deadline)
// defer cancel()

timeoutContext, cancel := context.WithTimeout(context.TODO(), timeout)
defer cancel()

// Watch status information for checking latency
Expand Down Expand Up @@ -217,7 +222,7 @@ func main() {
var twg sync.WaitGroup

twg.Add(1)
doScheduledTest(ctx, &twg)
doScheduledTest(timeoutContext, &twg)
twg.Wait()

option = "q"
Expand Down Expand Up @@ -580,7 +585,7 @@ func doInteractiveTest() {
CBLogger.Debug("End.........")
}

func doScheduledTest(ctxDeadline context.Context, wg *sync.WaitGroup) {
func doScheduledTest(ctx context.Context, wg *sync.WaitGroup) error {
CBLogger.Debug("Start.........")
defer wg.Done()

Expand All @@ -598,24 +603,36 @@ func doScheduledTest(ctxDeadline context.Context, wg *sync.WaitGroup) {
elapsed := time.Since(start)
CBLogger.Debugf("Elapsed time: %s", elapsed)

CBLogger.Debug("Sleep 30 sec ( _ _ )zZ to test securely")
time.Sleep(30 * time.Second)
CBLogger.Info("Sleep 1 min ( _ _ )zZ to test securely")
time.Sleep(1 * time.Minute)
}

CBLogger.Infof("(Trial: %d) End test and sleep", trialNo)

nextStartTime := time.Now().Add(duration)
CBLogger.Trace(deadline)
CBLogger.Trace(nextStartTime)

if deadline.Before(nextStartTime) {
CBLogger.Info("The scheduled test is finished (by remaining time measurement).")
CBLogger.Debug("End.........")
return errors.New("not enough time")
}

ticker := time.NewTicker(duration)

// While
for {
// NOTE - Default Selection
// The default case in a select is run if no other case is ready.
// Use a default case to try a send or receive without blocking:

select {
case <-ctxDeadline.Done():
CBLogger.Info("The scheduled test is finished.")
case <-ctx.Done():
CBLogger.Info("The scheduled test is finished (by timeout).")
CBLogger.Debug("End.........")
return
case <-time.After(1 * time.Hour):
return nil
case <-ticker.C:

trialNo = trialNo + 1

Expand All @@ -628,13 +645,23 @@ func doScheduledTest(ctxDeadline context.Context, wg *sync.WaitGroup) {
handleOption(strconv.Itoa(i))

elapsed := time.Since(start)
CBLogger.Debugf("Elapsed time: %s\n", elapsed)
CBLogger.Debugf("Elapsed time: %s", elapsed)

CBLogger.Debug("Sleep 30 sec ( _ _ )zZ to test securely")
time.Sleep(30 * time.Second)
CBLogger.Info("Sleep 1 min ( _ _ )zZ to test securely")
time.Sleep(1 * time.Minute)
}

CBLogger.Infof("(Trial: %d) End test and sleep", trialNo)

nextStartTime := time.Now().Add(duration)
CBLogger.Trace(deadline)
CBLogger.Trace(nextStartTime)

if deadline.Before(nextStartTime) {
CBLogger.Info("The scheduled test is finished (by remaining time measurement).")
CBLogger.Debug("End.........")
return errors.New("not enough time")
}
}
}
}
Expand Down Expand Up @@ -764,8 +791,8 @@ func resumeMCIS() {
CBLogger.Tracef("\nBody: %v", resp)

// Check if all VMs run
CBLogger.Info("Check MCIS status for 150 seconds (interval: 15 seconds)")
ctx, cancel := context.WithTimeout(context.TODO(), 150*time.Second)
CBLogger.Infof("Check MCIS status for %v seconds (interval: %v seconds)", timeoutToCheckMCIS, durationToCheckMCIS)
ctx, cancel := context.WithTimeout(context.TODO(), timeoutToCheckMCIS)
defer cancel()

err = checkRunning(ctx)
Expand All @@ -780,12 +807,14 @@ func resumeMCIS() {
func checkRunning(ctx context.Context) error {
CBLogger.Debug("Start.........")

ticker := time.NewTicker(durationToCheckMCIS)

for {
select {
case <-ctx.Done():
CBLogger.Debug("End.........")
return errors.New("timeout")
case <-time.After(15 * time.Second):
case <-ticker.C:
status := checkStatusOfMCIS()

isRunning := strings.Contains(status, "Running")
Expand Down Expand Up @@ -857,8 +886,8 @@ func suspendMCIS() {
CBLogger.Tracef("\nBody: %v", resp)

// Check if all VMs are suspended
CBLogger.Info("Check MCIS status for 150 seconds (interval: 15 seconds)")
ctx, cancel := context.WithTimeout(context.TODO(), 150*time.Second)
CBLogger.Infof("Check MCIS status for %v seconds (interval: %v seconds)", timeoutToCheckMCIS, durationToCheckMCIS)
ctx, cancel := context.WithTimeout(context.TODO(), timeoutToCheckMCIS)
defer cancel()

err = checkSuspended(ctx)
Expand All @@ -874,12 +903,14 @@ func suspendMCIS() {
func checkSuspended(ctx context.Context) error {
CBLogger.Debug("Start.........")

ticker := time.NewTicker(durationToCheckMCIS)

for {
select {
case <-ctx.Done():
CBLogger.Debug("End.........")
return errors.New("timeout")
case <-time.After(15 * time.Second):
case <-ticker.C:
status := checkStatusOfMCIS()

isRunning := strings.Contains(status, "Suspended")
Expand Down

0 comments on commit a77a37d

Please sign in to comment.