PerSystSqlOperator.cpp 6.54 KB
Newer Older
1
//================================================================================
2
// Name        : PerSystSqlOperator.cpp
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Author      : Carla Guillen
// Contact     : info@dcdb.it
// Copyright   : Leibniz Supercomputing Centre
// Description : Template implementing features to use Units in Operators.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2018-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================

#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/formatting_ostream.hpp>
#include <boost/parameter/keyword.hpp>
#include <stddef.h>
#include <sys/types.h>
#include <cstdint>
#include <string>

#include "../../../common/include/logging.h"
#include "../../../common/include/timestamp.h"
#include "../../includes/CommonStatistics.h"
#include "../../includes/QueryEngine.h"
41
#include "PerSystSqlOperator.h"
42

43
PerSystSqlOperator::PerSystSqlOperator(const std::string& name) :
44
45
46
		OperatorTemplate(name), JobOperatorTemplate(name), _number_of_even_quantiles(0),
		_severity_formula(NOFORMULA), _severity_threshold(0), _severity_exponent(0),
		_severity_max_memory(0) {
47
48
}

49
PerSystSqlOperator::~PerSystSqlOperator() {
50
51
}

52
void PerSystSqlOperator::compute(U_Ptr unit, qeJobData& jobData) {
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    // Clearing the buffer, if already allocated
	_buffer.clear();
    size_t elCtr=0;
    uint64_t my_timestamp = getTimestamp(); //TODO minus 10 seconds or so...
    // Making sure that the aggregation boundaries do not go past the job start/end time
    uint64_t jobEnd   = jobData.endTime!=0 && my_timestamp > jobData.endTime ? jobData.endTime : my_timestamp;
    uint64_t jobStart = jobEnd-my_timestamp < jobData.startTime ? jobData.startTime : jobEnd-my_timestamp;
    // Job units are hierarchical, and thus we iterate over all sub-units associated to each single node
    for(const auto& subUnit : unit->getSubUnits()) {
        // Getting the most recent values as specified in _window
        // Since we do not clear the internal buffer, all sensor readings will be accumulated in the same vector
        for(const auto& in : subUnit->getInputs()) {
            elCtr = _buffer.size();
            _queryEngine.querySensor(in->getName(), my_timestamp, my_timestamp, _buffer, false);
            if (_buffer.size() <= elCtr) {
                LOG(debug) << "Job Operator " << _name << " cannot read from sensor " << in->getName() << "!";
                return;
            }
        }
    }
    compute_internal(unit, _buffer);
}

76
void PerSystSqlOperator::compute_internal(U_Ptr unit, vector<reading_t> buffer) {
Carla Guillen Carias's avatar
Carla Guillen Carias committed
77
	_quantileSensors.clear();
78
79
    reading_t reading;
    AggregatorSensorBase::aggregationOps_t op;
80
    reading.timestamp = getTimestamp() - 10e9;
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    // Performing the actual aggregation operation
    for(const auto& out : unit->getOutputs()) {
        op = out->getOperation();
        if(op!=AggregatorSensorBase::QTL) {
            switch (op) {
                case AggregatorSensorBase::SUM:
                    reading.value = computeSum(buffer);
                    break;
                case AggregatorSensorBase::AVG:
                    reading.value = computeAvg(buffer);
                    break;
                case AggregatorSensorBase::MIN:
                    reading.value = computeMin(buffer);
                    break;
                case AggregatorSensorBase::MAX:
                    reading.value = computeMax(buffer);
                    break;
                case AggregatorSensorBase::STD:
                    reading.value = computeStd(buffer);
                    break;
                case AggregatorSensorBase::OBS:
                    reading.value = computeObs(buffer);
                    break;
104
105
106
                case AggregatorSensorBase::AVG_SEV:
                	reading.value = computeSeverityAverage(buffer);
                	break;
107
108
109
110
111
112
                default:
                    LOG(warning) << _name << ": Encountered unknown operation!";
                    reading.value = 0;
                    break;
            }
            out->storeReading(reading);
Carla Guillen Carias's avatar
Carla Guillen Carias committed
113
114
        } else {
        	_quantileSensors.push_back(out);
115
116
117
118
119
        }
    }

    if(!_quantileSensors.empty()) {
    	vector<int64_t> quantiles;
120
      	computeEvenQuantiles(buffer, _number_of_even_quantiles, quantiles);
121
122
123
124
125
126
127
        for(unsigned idx=0; idx<quantiles.size(); idx++) {
            reading.value = quantiles[idx];
            _quantileSensors[idx]->storeReading(reading);
        }
    }
}

128
void PerSystSqlOperator::compute(U_Ptr unit){
129
130
//nothing here!
}
Carla Guillen Carias's avatar
Carla Guillen Carias committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

float severity_formula1(float metric, float threshold, float exponent){
	float val = metric - threshold;
	if (val > 0) {
		float ret = (pow(val, exponent));
		if(ret > 1){
			return 1;
		}
		return ret;
	}
	return 0;
}

float severity_formula2(float metric, float threshold, float exponent){
	if(!threshold){
		return -1;
	}
	float val = metric / threshold - 1;
	if (val > 0) {
		float ret= (pow(val, exponent));
		if(ret > 1){
			return 1;
		}
		return ret;
	}
	return 0;
}

float severity_formula3(float metric, float threshold, float exponent){
	if (!threshold) {
		return -1;
	}
	float val = metric / threshold;
	if (val > 0) {
		float ret= (1 - pow(val, exponent));
		if(ret > 1 ){
			return 1;
		}
		if( ret < 0 ){
			return 0;
		}
		return ret;
	}
	return 0;
}

float severity_memory(float metric, float threshold, float max_memory){
	float denominator = max_memory - threshold;
	float severity = -1;
	if(denominator){
		severity = metric - threshold/(max_memory - threshold);
		if(severity > 1) {
			severity = 1;
		} else if(severity < 0){
			severity = 0;
		}
	}
	return severity;
}
190

Carla Guillen's avatar
Carla Guillen committed
191
192
int64_t PerSystSqlOperator::computeSeverityAverage(vector<reading_t> & buffer){
	return 0;
193
}