-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lazar Cvetković <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,084 additions
and
480 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
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,110 @@ | ||
package driver | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/vhive-serverless/loader/pkg/common" | ||
mc "github.com/vhive-serverless/loader/pkg/metric" | ||
"math" | ||
"os" | ||
"sync" | ||
"time" | ||
) | ||
|
||
func (d *Driver) CreateMetricsScrapper(interval time.Duration, | ||
signalReady *sync.WaitGroup, finishCh chan int, allRecordsWritten *sync.WaitGroup) func() { | ||
timer := time.NewTicker(interval) | ||
|
||
return func() { | ||
signalReady.Done() | ||
knStatRecords := make(chan interface{}, 100) | ||
scaleRecords := make(chan interface{}, 100) | ||
writerDone := sync.WaitGroup{} | ||
|
||
clusterUsageFile, err := os.Create(d.outputFilename("cluster_usage")) | ||
common.Check(err) | ||
defer clusterUsageFile.Close() | ||
|
||
writerDone.Add(1) | ||
go d.runCSVWriter(knStatRecords, d.outputFilename("kn_stats"), &writerDone) | ||
|
||
writerDone.Add(1) | ||
go d.runCSVWriter(scaleRecords, d.outputFilename("deployment_scale"), &writerDone) | ||
|
||
for { | ||
select { | ||
case <-timer.C: | ||
recCluster := mc.ScrapeClusterUsage() | ||
recCluster.Timestamp = time.Now().UnixMicro() | ||
|
||
byteArr, err := json.Marshal(recCluster) | ||
common.Check(err) | ||
|
||
_, err = clusterUsageFile.Write(byteArr) | ||
common.Check(err) | ||
|
||
_, err = clusterUsageFile.WriteString("\n") | ||
common.Check(err) | ||
|
||
recScale := mc.ScrapeDeploymentScales() | ||
timestamp := time.Now().UnixMicro() | ||
for _, rec := range recScale { | ||
rec.Timestamp = timestamp | ||
scaleRecords <- rec | ||
} | ||
|
||
recKnative := mc.ScrapeKnStats() | ||
recKnative.Timestamp = time.Now().UnixMicro() | ||
knStatRecords <- recKnative | ||
case <-finishCh: | ||
close(knStatRecords) | ||
close(scaleRecords) | ||
|
||
writerDone.Wait() | ||
allRecordsWritten.Done() | ||
|
||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (d *Driver) createGlobalMetricsCollector(filename string, collector chan *mc.ExecutionRecord, | ||
signalReady *sync.WaitGroup, signalEverythingWritten *sync.WaitGroup, totalIssuedChannel chan int64) { | ||
|
||
// NOTE: totalNumberOfInvocations is initialized to MaxInt64 not to allow collector to complete before | ||
// the end signal is received on totalIssuedChannel, which deliver the total number of issued invocations. | ||
// This number is known once all the individual function drivers finish issuing invocations and | ||
// when all the invocations return | ||
var totalNumberOfInvocations int64 = math.MaxInt64 | ||
var currentlyWritten int64 | ||
|
||
file, err := os.Create(filename) | ||
common.Check(err) | ||
defer file.Close() | ||
|
||
signalReady.Done() | ||
|
||
records := make(chan interface{}, 100) | ||
writerDone := sync.WaitGroup{} | ||
writerDone.Add(1) | ||
go d.runCSVWriter(records, filename, &writerDone) | ||
|
||
for { | ||
select { | ||
case record := <-collector: | ||
records <- record | ||
|
||
currentlyWritten++ | ||
case record := <-totalIssuedChannel: | ||
totalNumberOfInvocations = record | ||
} | ||
|
||
if currentlyWritten == totalNumberOfInvocations { | ||
close(records) | ||
writerDone.Wait() | ||
(*signalEverythingWritten).Done() | ||
|
||
return | ||
} | ||
} | ||
} |
Oops, something went wrong.