Commit 9c86d7e9 authored by Simon Pastor's avatar Simon Pastor
Browse files

log optimization

parent 71ea73af
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ func (u *destination) compute() (st stat) {
	return
}

func (u *destination) processRxTx(ifbStatsStr string) {
func (u *destination) processRxTx(ifbStatsStr string) float64 {

	// Retrieve ifb statistics from passed string
	// NOTE: we have to read the ifbStats from the back since based on the results are always at
@@ -181,14 +181,7 @@ func (u *destination) processRxTx(ifbStatsStr string) {
	u.prevRx.time = curTime
	u.prevRx.rxBytes = curRxBytes

	// Store throughput metric if entry exists
	var tputStats = make(map[string]interface{})
	tputStats[u.remoteName] = tput
	key := moduleMetrics + ":" + PodName + ":throughput"

	if rc.EntryExists(key) {
		_ = rc.SetEntry(key, tputStats)
	}
	return tput
}

func (u *destination) logRxTx(ifbStatsStr string) {
+24 −6
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ var metricStore *ms.MetricStore
const DEFAULT_SIDECAR_DB = 0

var nbAppliedSetIfbs = 0
var nbAppliedOperations = 0

// Run - MEEP Sidecar execution
func main() {
@@ -245,9 +246,10 @@ func refreshNetCharRules() {
	_ = initializeOnFirstPass()

	currentTime := time.Now()
	nbAppliedSetIfbs = 0
	nbAppliedOperations = 0

	_ = createIfbs()

	_ = createFilters()

	// Delete unused filters
@@ -257,8 +259,7 @@ func refreshNetCharRules() {
	deleteUnusedIfbs()

	elapsed := time.Since(currentTime)

	log.Debug("RefreshNetCharRules execution time for ", nbAppliedSetIfbs, " updates, elapsed time: ", elapsed)
	log.Debug("RefreshNetCharRules execution time for ", nbAppliedOperations, " updates, elapsed time: ", elapsed)

	// Start measurements
	startMeasurementThreads()
@@ -601,12 +602,22 @@ func workRxTxPackets() {
			lineIndex = lineIndex + 3
		}

		// Store throughput metric if entry exists
		var tputStats = make(map[string]interface{})

		for _, u := range opts.dests {
			//get the data for all, parse the output and transmit to each
			//starting 1 thread for getting the rx-tx info and computing the appropriate metrics
			/*go*/
			u.processRxTx(qdiscResults["ifb"+u.ifbNumber])
			tputStats[u.remoteName] = u.processRxTx(qdiscResults["ifb"+u.ifbNumber])
		}

		key := moduleMetrics + ":" + PodName + ":throughput"

		if rc.EntryExists(key) {
			_ = rc.SetEntry(key, tputStats)
		}

		semOptsDests.Unlock()

		time.Sleep(opts.trafficInterval)
@@ -794,6 +805,7 @@ func cmdCreateIfb(shape map[string]string) error {

	//"ip link add $ifb$ifbnumber type ifb"
	str := "ip link add ifb" + ifbNumber + " type ifb"
	nbAppliedOperations++
	_, err := cmdExec(str)
	if err != nil {
		log.Info("ERROR ifb" + ifbNumber + " already exist in sidecar")
@@ -802,6 +814,7 @@ func cmdCreateIfb(shape map[string]string) error {

	//"ip link set $ifb$ifbnumber up"
	str = "ip link set ifb" + ifbNumber + " up"
	nbAppliedOperations++
	_, err = cmdExec(str)
	if err != nil {
		return err
@@ -809,6 +822,7 @@ func cmdCreateIfb(shape map[string]string) error {

	//"tc qdisc replace dev $ifb$ifbnumber handle 1:0 root netem"
	str = "tc qdisc replace dev ifb" + ifbNumber + " handle 1:0 root netem"
	nbAppliedOperations++
	_, err = cmdExec(str)
	if err != nil {
		return err
@@ -857,7 +871,7 @@ func cmdSetIfb(shape map[string]string) (bool, error) {
		if dataRate != "" && dataRate != "0" {
			str = str + " rate " + dataRate + "bit"
		}

		nbAppliedOperations++
		_, err := cmdExec(str)
		if err != nil {
			return false, err
@@ -877,6 +891,7 @@ func cmdSetIfb(shape map[string]string) (bool, error) {
func cmdDeleteIfb(ifbNumber string) error {
	//"ip link delete ifb$ifbNumber"
	str := "ip link delete ifb" + ifbNumber
	nbAppliedOperations++
	_, err := cmdExec(str)
	if err != nil {
		return err
@@ -896,6 +911,7 @@ func cmdDeleteIfb(ifbNumber string) error {
func cmdDeleteFilter(filterNumber string) error {
	//tc filter del dev eth0 parent ffff: pref $filterNumber
	str := "tc filter del dev eth0 parent ffff: pref " + filterNumber
	nbAppliedOperations++
	_, err := cmdExec(str)
	if err != nil {
		return err
@@ -906,12 +922,13 @@ func cmdDeleteFilter(filterNumber string) error {
func initializeOnFirstPass() error {

	if firstTimePass {
		nbAppliedOperations++
		_, err := cmdExec("tc qdisc replace dev eth0 root handle 1: netem")
		if err != nil {
			log.Info("Error: ", err)
			return err
		}

		nbAppliedOperations++
		_, err = cmdExec("tc qdisc replace dev eth0 handle ffff: ingress")
		if err != nil {
			log.Info("Error: ", err)
@@ -930,6 +947,7 @@ func cmdCreateFilter(filterNumber string, ifbNumber string, ipSrc string) error
	//fonction must be a replace... a replace Adds if not there or replace if existing
	//"tc filter replace dev eth0 parent ffff: protocol ip prio $filterNumber u32 match ip src $ipsrc match u32 0 0 action mirred egress redirect dev $ifb$ifbnumber"
	//str := "tc filter replace dev eth0 parent ffff: protocol ip prio " + filterNumber + " handle 800::800 u32 match u32 0 0 action mirred egress redirect dev ifb" + ifbNumber
	nbAppliedOperations++
	_, err := cmdExec(str)
	if err != nil {
		log.Info("Error: ", err)
+2 −2
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ func (rc *Connector) JSONGetList(elem1 string, elem2 string, elementPath string,
	keyName := elementPath + "*"
	err := rc.ForEachJSONEntry(keyName, elem1, elem2, entryHandler, dataList)
	if err != nil {
		log.Error(err.Error())
		log.Error("keyName: ", keyName, ": ", err.Error())
		return err
	}
	return nil
@@ -264,7 +264,7 @@ func (rc *Connector) JSONSetEntry(key string, path string, json string) error {
	// Update existing entry or create new entry if it does not exist
	_, err := rc.client.JsonSet(key, path, json).Result()
	if err != nil {
		log.Error(err.Error())
		log.Error("key: ", key, ": ", err.Error())
		return err
	}
	return nil