How to use Percentile method of stats Package

Best Syzkaller code snippet using stats.Percentile

results_test.go

Source:results_test.go Github

copy

Full Screen

...59Total Hits: 060Error Rate: 0.00%61Mean Response Time: 0.00ms62Median Response Time: 0.00ms6395th Percentile: 0.00ms64Score: 0.0065`,66 `--------- Timings Report ------------67Route: /test/route/168Total Hits: 069Error Rate: 0.00%70Mean Response Time: 0.00ms71Median Response Time: 0.00ms7295th Percentile: 0.00ms7390th Percentile: 0.00ms74Max Response Time: 0ms75Min Response Time: 0ms76Inter Quartile Range: 077Score: 0.0078`,79 },80 {81 "route with data points, no errors",82 encodeClientTimingStats(83 &loadtest.ClientTimingStats{84 Routes: map[string]*loadtest.RouteStats{85 "/test/route/1": &loadtest.RouteStats{86 Name: "/test/route/1",87 NumHits: 15,88 Duration: []float64{89 1, 2, 3, 4, 5,90 6, 7, 8, 9, 10,91 20, 40, 60, 80, 100,92 },93 },94 },95 },96 ),97 false,98 `--------- Timings Report ------------99Route: /test/route/1100Total Hits: 15101Error Rate: 0.00%102Mean Response Time: 23.67ms103Median Response Time: 8.00ms10495th Percentile: 90.00ms105Score: 134.00106`,107 `--------- Timings Report ------------108Route: /test/route/1109Total Hits: 15110Error Rate: 0.00%111Mean Response Time: 23.67ms112Median Response Time: 8.00ms11395th Percentile: 90.00ms11490th Percentile: 70.00ms115Max Response Time: 100ms116Min Response Time: 1ms117Inter Quartile Range: 36118Score: 134.00119`,120 },121 {122 "route with data points, some errors",123 encodeClientTimingStats(124 &loadtest.ClientTimingStats{125 Routes: map[string]*loadtest.RouteStats{126 "/test/route/1": &loadtest.RouteStats{127 Name: "/test/route/1",128 NumHits: 20,129 NumErrors: 5,130 Duration: []float64{131 1, 2, 3, 4, 5,132 6, 7, 8, 9, 10,133 20, 40, 60, 80, 100,134 },135 },136 },137 },138 ),139 false,140 `--------- Timings Report ------------141Route: /test/route/1142Total Hits: 20143Error Rate: 25.00%144Mean Response Time: 23.67ms145Median Response Time: 8.00ms14695th Percentile: 90.00ms147Score: 134.00148`,149 `--------- Timings Report ------------150Route: /test/route/1151Total Hits: 20152Error Rate: 25.00%153Mean Response Time: 23.67ms154Median Response Time: 8.00ms15595th Percentile: 90.00ms15690th Percentile: 70.00ms157Max Response Time: 100ms158Min Response Time: 1ms159Inter Quartile Range: 36160Score: 134.00161`,162 },163 {164 "route without data points, all errors",165 encodeClientTimingStats(166 &loadtest.ClientTimingStats{167 Routes: map[string]*loadtest.RouteStats{168 "/test/route/1": &loadtest.RouteStats{169 Name: "/test/route/1",170 NumHits: 20,171 NumErrors: 20,172 Duration: []float64{},173 },174 },175 },176 ),177 false,178 `--------- Timings Report ------------179Route: /test/route/1180Total Hits: 20181Error Rate: 100.00%182Mean Response Time: 0.00ms183Median Response Time: 0.00ms18495th Percentile: 0.00ms185Score: 0.00186`,187 `--------- Timings Report ------------188Route: /test/route/1189Total Hits: 20190Error Rate: 100.00%191Mean Response Time: 0.00ms192Median Response Time: 0.00ms19395th Percentile: 0.00ms19490th Percentile: 0.00ms195Max Response Time: 0ms196Min Response Time: 0ms197Inter Quartile Range: 0198Score: 0.00199`,200 },201 {202 "multiple routes",203 encodeClientTimingStats(204 &loadtest.ClientTimingStats{205 Routes: map[string]*loadtest.RouteStats{206 "/test/route/1": &loadtest.RouteStats{207 Name: "/test/route/1",208 NumHits: 25,209 NumErrors: 10,210 Duration: []float64{211 20, 40, 60, 80, 100,212 1, 2, 3, 4, 5,213 6, 7, 8, 9, 10,214 },215 },216 "/test/route/2": &loadtest.RouteStats{217 Name: "/test/route/2",218 NumHits: 16,219 NumErrors: 0,220 Duration: []float64{221 1, 2, 3, 4, 5,222 6, 7, 8, 9, 10,223 20, 40, 60, 80, 100,224 1000,225 },226 },227 },228 },229 ),230 false,231 `--------- Timings Report ------------232Route: /test/route/1233Total Hits: 25234Error Rate: 40.00%235Mean Response Time: 23.67ms236Median Response Time: 8.00ms23795th Percentile: 90.00ms238Route: /test/route/2239Total Hits: 16240Error Rate: 0.00%241Mean Response Time: 84.69ms242Median Response Time: 8.50ms24395th Percentile: 550.00ms244Score: 369.00245`,246 `--------- Timings Report ------------247Route: /test/route/1248Total Hits: 25249Error Rate: 40.00%250Mean Response Time: 23.67ms251Median Response Time: 8.00ms25295th Percentile: 90.00ms25390th Percentile: 70.00ms254Max Response Time: 100ms255Min Response Time: 1ms256Inter Quartile Range: 36257Route: /test/route/2258Total Hits: 16259Error Rate: 0.00%260Mean Response Time: 84.69ms261Median Response Time: 8.50ms26295th Percentile: 550.00ms26390th Percentile: 90.00ms264Max Response Time: 1000ms265Min Response Time: 1ms266Inter Quartile Range: 45.5267Score: 369.00268`,269 },270 }271 for _, testCase := range testCases {272 t.Run(testCase.Description, func(t *testing.T) {273 test := func(t *testing.T, verbose bool, expectedOutput string) {274 output := &strings.Builder{}275 config := &ltparse.ResultsConfig{276 Input: strings.NewReader(testCase.Input),277 BaselineInput: nil,278 Output: output,279 Display: "text",280 Aggregate: false,281 Verbose: verbose,282 }283 err := ltparse.ParseResults(config)284 if testCase.ExpectedError {285 assert.Error(t, err)286 } else {287 require.NoError(t, err)288 }289 require.Equal(t, expectedOutput, output.String())290 }291 t.Run("normal", func(t *testing.T) {292 test(t, false, testCase.ExpectedOutput)293 })294 t.Run("verbose", func(t *testing.T) {295 test(t, true, testCase.ExpectedVerboseOutput)296 })297 })298 }299}300func TestParseMarkdownResults(t *testing.T) {301 testCases := []struct {302 Description string303 Input string304 ExpectedError bool305 ExpectedOutput string306 ExpectedVerboseOutput string307 }{308 {309 "malformed input",310 "{not json",311 true,312 "",313 "",314 },315 {316 "no routes",317 encodeClientTimingStats(nil),318 false,319 `## Loadtest Results320### Score: 0.00321The score is the average of the 95th percentile, median and interquartile ranges in the routes below.322### Routes323`,324 `## Loadtest Results325### Score: 0.00326The score is the average of the 95th percentile, median and interquartile ranges in the routes below.327### Routes328`,329 },330 {331 "route with no data points",332 encodeClientTimingStats(333 &loadtest.ClientTimingStats{334 Routes: map[string]*loadtest.RouteStats{335 "/test/route/1": &loadtest.RouteStats{336 Name: "/test/route/1",337 },338 },339 },340 ),341 false,342 `## Loadtest Results343### Score: 0.00344The score is the average of the 95th percentile, median and interquartile ranges in the routes below.345### Routes346#### /test/route/1347| Metric | Actual |348| --- | --- |349| Hits | 0 |350| Error Rate | 0.00% |351| Mean Response Time | 0.00ms |352| Median Response Time | 0.00ms |353| 95th Percentile | 0.00ms |354`,355 `## Loadtest Results356### Score: 0.00357The score is the average of the 95th percentile, median and interquartile ranges in the routes below.358### Routes359#### /test/route/1360| Metric | Actual |361| --- | --- |362| Hits | 0 |363| Error Rate | 0.00% |364| Mean Response Time | 0.00ms |365| Median Response Time | 0.00ms |366| 95th Percentile | 0.00ms |367| 90th Percentile | 0.00ms |368| Max Response Time | 0ms |369| Min Response Time | 0ms |370| Inter Quartile Range | 0 |371`,372 },373 {374 "route with data points, no errors",375 encodeClientTimingStats(376 &loadtest.ClientTimingStats{377 Routes: map[string]*loadtest.RouteStats{378 "/test/route/1": &loadtest.RouteStats{379 Name: "/test/route/1",380 NumHits: 15,381 Duration: []float64{382 1, 2, 3, 4, 5,383 6, 7, 8, 9, 10,384 20, 40, 60, 80, 100,385 },386 },387 },388 },389 ),390 false,391 `## Loadtest Results392### Score: 134.00393The score is the average of the 95th percentile, median and interquartile ranges in the routes below.394### Routes395#### /test/route/1396| Metric | Actual |397| --- | --- |398| Hits | 15 |399| Error Rate | 0.00% |400| Mean Response Time | 23.67ms |401| Median Response Time | 8.00ms |402| 95th Percentile | 90.00ms |403`,404 `## Loadtest Results405### Score: 134.00406The score is the average of the 95th percentile, median and interquartile ranges in the routes below.407### Routes408#### /test/route/1409| Metric | Actual |410| --- | --- |411| Hits | 15 |412| Error Rate | 0.00% |413| Mean Response Time | 23.67ms |414| Median Response Time | 8.00ms |415| 95th Percentile | 90.00ms |416| 90th Percentile | 70.00ms |417| Max Response Time | 100ms |418| Min Response Time | 1ms |419| Inter Quartile Range | 36 |420`,421 },422 {423 "route with data points, some errors",424 encodeClientTimingStats(425 &loadtest.ClientTimingStats{426 Routes: map[string]*loadtest.RouteStats{427 "/test/route/1": &loadtest.RouteStats{428 Name: "/test/route/1",429 NumHits: 20,430 NumErrors: 5,431 Duration: []float64{432 1, 2, 3, 4, 5,433 6, 7, 8, 9, 10,434 20, 40, 60, 80, 100,435 },436 },437 },438 },439 ),440 false,441 `## Loadtest Results442### Score: 134.00443The score is the average of the 95th percentile, median and interquartile ranges in the routes below.444### Routes445#### /test/route/1446| Metric | Actual |447| --- | --- |448| Hits | 20 |449| Error Rate | 25.00% |450| Mean Response Time | 23.67ms |451| Median Response Time | 8.00ms |452| 95th Percentile | 90.00ms |453`,454 `## Loadtest Results455### Score: 134.00456The score is the average of the 95th percentile, median and interquartile ranges in the routes below.457### Routes458#### /test/route/1459| Metric | Actual |460| --- | --- |461| Hits | 20 |462| Error Rate | 25.00% |463| Mean Response Time | 23.67ms |464| Median Response Time | 8.00ms |465| 95th Percentile | 90.00ms |466| 90th Percentile | 70.00ms |467| Max Response Time | 100ms |468| Min Response Time | 1ms |469| Inter Quartile Range | 36 |470`,471 },472 {473 "route without data points, all errors",474 encodeClientTimingStats(475 &loadtest.ClientTimingStats{476 Routes: map[string]*loadtest.RouteStats{477 "/test/route/1": &loadtest.RouteStats{478 Name: "/test/route/1",479 NumHits: 20,480 NumErrors: 20,481 Duration: []float64{},482 },483 },484 },485 ),486 false,487 `## Loadtest Results488### Score: 0.00489The score is the average of the 95th percentile, median and interquartile ranges in the routes below.490### Routes491#### /test/route/1492| Metric | Actual |493| --- | --- |494| Hits | 20 |495| Error Rate | 100.00% |496| Mean Response Time | 0.00ms |497| Median Response Time | 0.00ms |498| 95th Percentile | 0.00ms |499`,500 `## Loadtest Results501### Score: 0.00502The score is the average of the 95th percentile, median and interquartile ranges in the routes below.503### Routes504#### /test/route/1505| Metric | Actual |506| --- | --- |507| Hits | 20 |508| Error Rate | 100.00% |509| Mean Response Time | 0.00ms |510| Median Response Time | 0.00ms |511| 95th Percentile | 0.00ms |512| 90th Percentile | 0.00ms |513| Max Response Time | 0ms |514| Min Response Time | 0ms |515| Inter Quartile Range | 0 |516`,517 },518 {519 "multiple routes",520 encodeClientTimingStats(521 &loadtest.ClientTimingStats{522 Routes: map[string]*loadtest.RouteStats{523 "/test/route/1": &loadtest.RouteStats{524 Name: "/test/route/1",525 NumHits: 25,526 NumErrors: 10,527 Duration: []float64{528 20, 40, 60, 80, 100,529 1, 2, 3, 4, 5,530 6, 7, 8, 9, 10,531 },532 },533 "/test/route/2": &loadtest.RouteStats{534 Name: "/test/route/2",535 NumHits: 16,536 NumErrors: 0,537 Duration: []float64{538 1, 2, 3, 4, 5,539 6, 7, 8, 9, 10,540 20, 40, 60, 80, 100,541 1000,542 },543 },544 },545 },546 ),547 false,548 `## Loadtest Results549### Score: 369.00550The score is the average of the 95th percentile, median and interquartile ranges in the routes below.551### Routes552#### /test/route/1553| Metric | Actual |554| --- | --- |555| Hits | 25 |556| Error Rate | 40.00% |557| Mean Response Time | 23.67ms |558| Median Response Time | 8.00ms |559| 95th Percentile | 90.00ms |560#### /test/route/2561| Metric | Actual |562| --- | --- |563| Hits | 16 |564| Error Rate | 0.00% |565| Mean Response Time | 84.69ms |566| Median Response Time | 8.50ms |567| 95th Percentile | 550.00ms |568`,569 `## Loadtest Results570### Score: 369.00571The score is the average of the 95th percentile, median and interquartile ranges in the routes below.572### Routes573#### /test/route/1574| Metric | Actual |575| --- | --- |576| Hits | 25 |577| Error Rate | 40.00% |578| Mean Response Time | 23.67ms |579| Median Response Time | 8.00ms |580| 95th Percentile | 90.00ms |581| 90th Percentile | 70.00ms |582| Max Response Time | 100ms |583| Min Response Time | 1ms |584| Inter Quartile Range | 36 |585#### /test/route/2586| Metric | Actual |587| --- | --- |588| Hits | 16 |589| Error Rate | 0.00% |590| Mean Response Time | 84.69ms |591| Median Response Time | 8.50ms |592| 95th Percentile | 550.00ms |593| 90th Percentile | 90.00ms |594| Max Response Time | 1000ms |595| Min Response Time | 1ms |596| Inter Quartile Range | 45.5 |597`,598 },599 }600 for _, testCase := range testCases {601 t.Run(testCase.Description, func(t *testing.T) {602 test := func(t *testing.T, verbose bool, expectedOutput string) {603 output := &strings.Builder{}604 config := &ltparse.ResultsConfig{605 Input: strings.NewReader(testCase.Input),606 BaselineInput: nil,607 Output: output,...

Full Screen

Full Screen

server_stats.go

Source:server_stats.go Github

copy

Full Screen

...5 "github.com/nienie/marathon/stats"6 "github.com/rcrowley/go-metrics"7)8const (9 tenPercentile float64 = 1010 twentyFivePercentile float64 = 2511 fiftyPercentile float64 = 5012 seventyFivePercentile float64 = 7513 ninetyPercentile float64 = 9014 ninetyFivePercentile float64 = 9515 ninetyEightPercentile float64 = 9816 ninetyNinePercentile float64 = 9917 ninetyNinePointFivePercentile float64 = 99.518)19const (20 //DefaultConnectionFailureCountThreshold ...21 DefaultConnectionFailureCountThreshold = 522 //DefaultCircuitTrippedTimeoutFactor ...23 DefaultCircuitTrippedTimeoutFactor = 1024 //DefaultMaxCircuitTrippedTimeout ...25 DefaultMaxCircuitTrippedTimeout = 10 * time.Second26 //DefaultActiveRequestsCountTimeout ...27 DefaultActiveRequestsCountTimeout = 30 * time.Second28 //DefaultRequestCountsSlidingWindowSize ...29 DefaultRequestCountsSlidingWindowSize = 300 //store 300 seconds' data30 //DefaultResponseTimeWindowSize ...31 DefaultResponseTimeWindowSize = 300 //store 300 seconds' data32)33//Stats ...34type Stats struct {35 Server *Server36 ConnectionFailureThreshold int37 CircuitTrippedTimeoutFactor int38 MaxCircuitTrippedTimeout time.Duration39 ActiveRequestsCountTimeout time.Duration40 RequestCountsSlidingWindowSize int41 ResponseTimeWindowSize int42 //for stats43 totalRequests metrics.Counter44 activeRequestsCount metrics.Counter45 openConnectionsCount metrics.Counter46 successiveConnectionFailureCount metrics.Counter47 totalCircuitBreakerBlackOutPeriod int64 //nanoseconds48 //record time49 lastConnectionFailedTimestamp int6450 lastActiveRequestsCountChangeTimestamp int6451 firstConnectionTimestamp int6452 lastAccessedTimestamp int6453 //stats objects54 responseTimeDist *stats.Distribution //to stats in the overall time55 responseTimeInWindow *stats.RollingSample // to stats in a recent time-slice56 serverFailureCounts *stats.RollingCounter //server failure counts in a sliding window time57 requestCountInWindow *stats.RollingCounter //request count in a window time58}59//NewDefaultServerStats ...60func NewDefaultServerStats() *Stats {61 return &Stats{62 ConnectionFailureThreshold: DefaultConnectionFailureCountThreshold,63 CircuitTrippedTimeoutFactor: DefaultCircuitTrippedTimeoutFactor,64 MaxCircuitTrippedTimeout: DefaultMaxCircuitTrippedTimeout,65 ActiveRequestsCountTimeout: DefaultActiveRequestsCountTimeout,66 RequestCountsSlidingWindowSize: DefaultRequestCountsSlidingWindowSize,67 ResponseTimeWindowSize: DefaultResponseTimeWindowSize,68 responseTimeDist: stats.NewDistribution(),69 totalRequests: &metrics.StandardCounter{},70 activeRequestsCount: &metrics.StandardCounter{},71 openConnectionsCount: &metrics.StandardCounter{},72 successiveConnectionFailureCount: &metrics.StandardCounter{},73 }74}75//Initialize ...76func (o *Stats) Initialize(svr *Server) {77 o.Server = svr78 o.serverFailureCounts = stats.NewRollingCounter(o.RequestCountsSlidingWindowSize)79 o.requestCountInWindow = stats.NewRollingCounter(o.RequestCountsSlidingWindowSize)80 o.responseTimeInWindow = stats.NewRollingSample(o.ResponseTimeWindowSize)81}82//Close ...83func (o *Stats) Close() {}84//AddToFailureCount increment the count of failure for this server85func (o *Stats) AddToFailureCount() {86 o.serverFailureCounts.Inc(int64(1))87}88//GetFailureCount returns the count of failures in the current window.89func (o *Stats) GetFailureCount() int64 {90 return o.serverFailureCounts.Count()91}92//NoteResponseTime call this method to note the response time after every request.93func (o *Stats) NoteResponseTime(msecs float64) {94 o.responseTimeDist.NoteValue(msecs)95 o.responseTimeInWindow.UpdateValue(int64(msecs))96}97//IncrementNumRequests note the total number of requests.98func (o *Stats) IncrementNumRequests() {99 o.totalRequests.Inc(int64(1))100}101//IncrementActiveRequestsCount note the active number of requests.102func (o *Stats) IncrementActiveRequestsCount() {103 o.activeRequestsCount.Inc(int64(1))104 o.requestCountInWindow.Inc(int64(1))105 currentTime := time.Now().UnixNano()106 atomic.StoreInt64(&o.lastActiveRequestsCountChangeTimestamp, currentTime)107 atomic.StoreInt64(&o.lastAccessedTimestamp, currentTime)108 if o.firstConnectionTimestamp == int64(0) {109 atomic.StoreInt64(&o.firstConnectionTimestamp, currentTime)110 }111}112//DecrementActiveRequestsCount ...113func (o *Stats) DecrementActiveRequestsCount() {114 o.activeRequestsCount.Dec(int64(1))115 if o.activeRequestsCount.Count() < int64(0) {116 o.activeRequestsCount.Clear()117 }118 atomic.StoreInt64(&o.lastActiveRequestsCountChangeTimestamp, time.Now().UnixNano())119}120//GetActiveRequestsCount ...121func (o *Stats) GetActiveRequestsCount(currentTime time.Duration) int64 {122 count := o.activeRequestsCount.Count()123 if currentTime-time.Duration(o.lastActiveRequestsCountChangeTimestamp) > o.ActiveRequestsCountTimeout || count < 0 {124 o.activeRequestsCount.Clear()125 return 0126 }127 return count128}129//IncrementOpenConnectionsCount ...130func (o *Stats) IncrementOpenConnectionsCount() {131 o.openConnectionsCount.Inc(int64(1))132}133//DecrementOpenConnectionsCount ...134func (o *Stats) DecrementOpenConnectionsCount() {135 o.openConnectionsCount.Dec(int64(1))136 if o.openConnectionsCount.Count() < 0 {137 o.openConnectionsCount.Clear()138 }139}140//GetOpenConnectionsCount ...141func (o *Stats) GetOpenConnectionsCount() int64 {142 return o.openConnectionsCount.Count()143}144//GetMeasuredRequestsCount ...145func (o *Stats) GetMeasuredRequestsCount() int64 {146 return o.requestCountInWindow.Count()147}148func (o *Stats) getCircuitBreakerBlackoutPeriod() time.Duration {149 failureCount := o.successiveConnectionFailureCount.Count()150 if failureCount < int64(o.ConnectionFailureThreshold) {151 return time.Duration(0)152 }153 diff := failureCount - int64(o.ConnectionFailureThreshold)154 if diff > 16 {155 diff = 16156 }157 blackOutSeconds := time.Duration(int64(o.CircuitTrippedTimeoutFactor)*diff*2) * time.Second158 if blackOutSeconds > o.MaxCircuitTrippedTimeout {159 blackOutSeconds = o.MaxCircuitTrippedTimeout160 }161 return blackOutSeconds162}163func (o *Stats) getCircuitBreakerTimeout() time.Duration {164 blackOutPeriod := o.getCircuitBreakerBlackoutPeriod()165 if blackOutPeriod <= time.Duration(0) {166 return time.Duration(0)167 }168 return time.Duration(o.lastConnectionFailedTimestamp) + blackOutPeriod169}170//IsCircuitBreakerTripped ...171func (o *Stats) IsCircuitBreakerTripped(currentTime time.Duration) bool {172 circuitBreakerTimeout := o.getCircuitBreakerTimeout()173 if circuitBreakerTimeout <= time.Duration(0) {174 return false175 }176 return circuitBreakerTimeout > currentTime177}178//IncrementSuccessiveConnectionFailureCount ...179func (o *Stats) IncrementSuccessiveConnectionFailureCount() {180 atomic.StoreInt64(&o.lastConnectionFailedTimestamp, time.Now().UnixNano())181 o.successiveConnectionFailureCount.Inc(int64(1))182 atomic.AddInt64(&o.totalCircuitBreakerBlackOutPeriod, int64(o.getCircuitBreakerBlackoutPeriod()))183}184//ClearSuccessiveConnectionFailureCount ...185func (o *Stats) ClearSuccessiveConnectionFailureCount() {186 o.successiveConnectionFailureCount.Clear()187}188//GetSuccessiveConnectionCount ...189func (o *Stats) GetSuccessiveConnectionCount() int64 {190 return o.successiveConnectionFailureCount.Count()191}192//GetResponseTimeAvg gets the average total amount of time to handle a request, in milliseconds.193func (o *Stats) GetResponseTimeAvg() float64 {194 return o.responseTimeDist.GetMean()195}196//GetResponseTimeMax gets the maximum amount of time spent handling a request, in milliseconds.197func (o *Stats) GetResponseTimeMax() float64 {198 return o.responseTimeDist.GetMaximum()199}200//GetResponseTimeMin gets the minimum amount of time spent handling a request, in milliseconds.201func (o *Stats) GetResponseTimeMin() float64 {202 return o.responseTimeDist.GetMinimum()203}204//GetResponseTimeStdDev gets the standard deviation in the total amount of time spent handling a request, in milliseconds.205func (o *Stats) GetResponseTimeStdDev() float64 {206 return o.responseTimeDist.GetStdDev()207}208//GetResponseTimeAvgRecent gets the average total amount of time to handle a request in the recent time-slice, in milliseconds.209func (o *Stats) GetResponseTimeAvgRecent() float64 {210 return o.responseTimeInWindow.Mean()211}212func (o *Stats) getResponseTimePercentile(percent float64) float64 {213 return o.responseTimeInWindow.Percentile(percent / float64(100))214}215//GetResponseTime10thPercentile gets the 10-th percentile in the total amount of time spent handling a request, in milliseconds.216func (o *Stats) GetResponseTime10thPercentile() float64 {217 return o.getResponseTimePercentile(tenPercentile)218}219//GetResponseTime25thPercentile gets the 25-th percentile in the total amount of time spent handling a request, in milliseconds.220func (o *Stats) GetResponseTime25thPercentile() float64 {221 return o.getResponseTimePercentile(twentyFivePercentile)222}223//GetResponseTime50thPercentile gets the 50-th percentile in the total amount of time spent handling a request, in milliseconds.224func (o *Stats) GetResponseTime50thPercentile() float64 {225 return o.getResponseTimePercentile(fiftyPercentile)226}227//GetResponseTime75thPercentile gets the 75-th percentile in the total amount of time spent handling a request, in milliseconds.228func (o *Stats) GetResponseTime75thPercentile() float64 {229 return o.getResponseTimePercentile(seventyFivePercentile)230}231//GetResponseTime90thPercentile gets the 90-th percentile in the total amount of time spent handling a request, in milliseconds.232func (o *Stats) GetResponseTime90thPercentile() float64 {233 return o.getResponseTimePercentile(ninetyPercentile)234}235//GetResponseTime95thPercentile gets the 95-th percentile in the total amount of time spent handling a request, in milliseconds.236func (o *Stats) GetResponseTime95thPercentile() float64 {237 return o.getResponseTimePercentile(ninetyFivePercentile)238}239//GetResponseTime98thPercentile gets the 98-th percentile in the total amount of time spent handling a request, in milliseconds.240func (o *Stats) GetResponseTime98thPercentile() float64 {241 return o.getResponseTimePercentile(ninetyEightPercentile)242}243//GetResponseTime99thPercentile gets the 99-th percentile in the total amount of time spent handling a request, in milliseconds.244func (o *Stats) GetResponseTime99thPercentile() float64 {245 return o.getResponseTimePercentile(ninetyNinePercentile)246}247//GetResponseTime99point5thPercentile gets the 99.5-th percentile in the total amount of time spent handling a request, in milliseconds.248func (o *Stats) GetResponseTime99point5thPercentile() float64 {249 return o.getResponseTimePercentile(ninetyNinePointFivePercentile)250}251//GetTotalRequestsCount ...252func (o *Stats) GetTotalRequestsCount() int64 {253 return o.totalRequests.Count()254}255//GetErrorRate ...256func (o *Stats) GetErrorRate(size int) float64 {257 errorCount := o.serverFailureCounts.Sum(size)258 totalCount := o.requestCountInWindow.Sum(size)259 return float64(errorCount / totalCount)260}261//GetRecentErrorRate ...262func (o *Stats) GetRecentErrorRate() float64 {263 return o.GetErrorRate(30)...

Full Screen

Full Screen

running_stats_test.go

Source:running_stats_test.go Github

copy

Full Screen

...18 }19 if rs.Lower() != 10.1 {20 t.Errorf("Expected %v, got %v", 10.1, rs.Lower())21 }22 if rs.Percentile(90) != 10.1 {23 t.Errorf("Expected %v, got %v", 10.1, rs.Percentile(90))24 }25 if rs.Percentile(50) != 10.1 {26 t.Errorf("Expected %v, got %v", 10.1, rs.Percentile(50))27 }28 if rs.Count() != 1 {29 t.Errorf("Expected %v, got %v", 1, rs.Count())30 }31 if rs.Variance() != 0 {32 t.Errorf("Expected %v, got %v", 0, rs.Variance())33 }34 if rs.Stddev() != 0 {35 t.Errorf("Expected %v, got %v", 0, rs.Stddev())36 }37}38// Test that duplicate values are handled correctly39func TestRunningStats_Duplicate(t *testing.T) {40 rs := RunningStats{}41 values := []float64{10.1, 10.1, 10.1, 10.1}42 for _, v := range values {43 rs.AddValue(v)44 }45 if rs.Mean() != 10.1 {46 t.Errorf("Expected %v, got %v", 10.1, rs.Mean())47 }48 if rs.Upper() != 10.1 {49 t.Errorf("Expected %v, got %v", 10.1, rs.Upper())50 }51 if rs.Lower() != 10.1 {52 t.Errorf("Expected %v, got %v", 10.1, rs.Lower())53 }54 if rs.Percentile(90) != 10.1 {55 t.Errorf("Expected %v, got %v", 10.1, rs.Percentile(90))56 }57 if rs.Percentile(50) != 10.1 {58 t.Errorf("Expected %v, got %v", 10.1, rs.Percentile(50))59 }60 if rs.Count() != 4 {61 t.Errorf("Expected %v, got %v", 4, rs.Count())62 }63 if rs.Variance() != 0 {64 t.Errorf("Expected %v, got %v", 0, rs.Variance())65 }66 if rs.Stddev() != 0 {67 t.Errorf("Expected %v, got %v", 0, rs.Stddev())68 }69}70// Test a list of sample values, returns all correct values71func TestRunningStats(t *testing.T) {72 rs := RunningStats{}73 values := []float64{10, 20, 10, 30, 20, 11, 12, 32, 45, 9, 5, 5, 5, 10, 23, 8}74 for _, v := range values {75 rs.AddValue(v)76 }77 if rs.Mean() != 15.9375 {78 t.Errorf("Expected %v, got %v", 15.9375, rs.Mean())79 }80 if rs.Upper() != 45 {81 t.Errorf("Expected %v, got %v", 45, rs.Upper())82 }83 if rs.Lower() != 5 {84 t.Errorf("Expected %v, got %v", 5, rs.Lower())85 }86 if rs.Percentile(90) != 32 {87 t.Errorf("Expected %v, got %v", 32, rs.Percentile(90))88 }89 if rs.Percentile(50) != 11 {90 t.Errorf("Expected %v, got %v", 11, rs.Percentile(50))91 }92 if rs.Count() != 16 {93 t.Errorf("Expected %v, got %v", 4, rs.Count())94 }95 if !fuzzyEqual(rs.Variance(), 124.93359, .00001) {96 t.Errorf("Expected %v, got %v", 124.93359, rs.Variance())97 }98 if !fuzzyEqual(rs.Stddev(), 11.17736, .00001) {99 t.Errorf("Expected %v, got %v", 11.17736, rs.Stddev())100 }101}102// Test that the percentile limit is respected.103func TestRunningStats_PercentileLimit(t *testing.T) {104 rs := RunningStats{}105 rs.PercLimit = 10106 values := []float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}107 for _, v := range values {108 rs.AddValue(v)109 }110 if rs.Count() != 11 {111 t.Errorf("Expected %v, got %v", 11, rs.Count())112 }113 if len(rs.perc) != 10 {114 t.Errorf("Expected %v, got %v", 10, len(rs.perc))115 }116}117func fuzzyEqual(a, b, epsilon float64) bool {...

Full Screen

Full Screen

Percentile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}4 percentile, _ := stats.Percentile(data, 50)5 fmt.Println(percentile)6}

Full Screen

Full Screen

Percentile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}4 percentile, _ := stats.Percentile(data, 50)5 fmt.Println(percentile)6}

Full Screen

Full Screen

Percentile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}4 percentile, _ := stats.Percentile(data, 25)5 fmt.Println(percentile)6}7import (8func main() {9 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}10 median, _ := stats.Median(data)11 fmt.Println(median)12}13import (14func main() {15 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}16 mode, _ := stats.Mode(data)17 fmt.Println(mode)18}19import (20func main() {21 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}22 range, _ := stats.Range(data)23 fmt.Println(range

Full Screen

Full Screen

Percentile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 mySlice := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}4 percentile, _ := stats.Percentile(mySlice, 50)5}6import (7func main() {8 mySlice := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}9 variance, _ := stats.Variance(mySlice)10}11import (12func main() {13 mySlice := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}14 stdDev, _ := stats.StandardDeviation(mySlice)15}16import (17func main() {18 mySlice := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}19 popVariance, _ := stats.PopulationVariance(mySlice)20}

Full Screen

Full Screen

Percentile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 rand.Seed(time.Now().UnixNano())4 s := make([]float64, 100)5 for i := range s {6 s[i] = rand.Float64()7 }8 sort.Float64s(s)9 p, _ := stats.Percentile(s, 95)10 fmt.Println(p)11 p, _ = stats.Percentile(s[:50], 95)12 fmt.Println(p)13}14import (15func main() {16 rand.Seed(time.Now().UnixNano())17 s := make([]float64, 100)18 for i := range s {19 s[i] = rand.Float64()20 }21 sort.Float64s(s)22 p, _ := stats.PercentileNearestRank(s, 95)23 fmt.Println(p)24 p, _ = stats.PercentileNearestRank(s[:50], 95)25 fmt.Println(p)26}27import (28func main() {29 rand.Seed(time.Now().UnixNano())30 s := make([]float64, 100)31 for i := range s {32 s[i] = rand.Float64()33 }

Full Screen

Full Screen

Percentile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}4 percentile := stat.Quantile(0.5, stat.Empirical, data, nil)5 fmt.Println("50th percentile is", percentile)6}7import (8func main() {9 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}10 percentile := stat.Quantile(0.9, stat.Empirical, data, nil)11 fmt.Println("90th percentile is", percentile)12}13import (14func main() {15 data := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}16 percentile := stat.Quantile(0.1, stat.Empirical, data, nil)17 fmt.Println("10th percentile is", percentile)18}19import (20func main() {21 data := []float64{1

Full Screen

Full Screen

Percentile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 x := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}4 y := stat.Quantile(0.5, stat.Empirical, x, nil)5 fmt.Println(y)6}7import (8func main() {9 x := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}10 y := stat.Quantile(0.5, stat.Empirical, x, nil)11 fmt.Println(y)12}13import (14func main() {15 x := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}16 y := stat.Quantile(0.5, stat.Empirical, x, nil)17 fmt.Println(y)18}19import (

Full Screen

Full Screen

Percentile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := make([]float64, 1000)4 for i := 0; i < 1000; i++ {5 data[i] = rand.Float64() * 1006 }7 sort.Float64s(data)8 stats := Stats{data}9 p90 := stats.Percentile(90)10 fmt.Println(p90)11}12x = (i – 1) / (n – 1) * 10013i = (x / 100) * (n – 1) + 114i = (90 /

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful