Skip to content

Commit

Permalink
[BACKPORT 2.14][PLAT-4187] Fix stdDevTime formula
Browse files Browse the repository at this point in the history
Summary:
Fix stdDevTime formula by adding square root.
(Previously was returning variance).

Original commit: 99983d2 / D17350

Test Plan:
- Run queries on a universe and check the slow queries tab
- Verify that the standard deviation is as expected

Reviewers: andrew, spotachev

Reviewed By: spotachev

Subscribers: yugaware, jenkins-bot

Differential Revision: https://phabricator.dev.yugabyte.com/D18594
  • Loading branch information
Jethro-M committed Jul 27, 2022
1 parent 42067c5 commit de7969e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions managed/src/main/java/com/yugabyte/yw/queries/QueryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,22 @@ public JsonNode query(
/*
* Formula to calculate std dev of two samples: Let mean, std dev, and size of
* sample A be X_a, S_a, n_a respectively; and mean, std dev, and size of sample B
* be X_b, S_b, n_b respectively. Then mean of combined sample X is given by n_a
* X_a + n_b X_b X = ----------------- n_a + n_b
* be X_b, S_b, n_b respectively. Then mean of combined sample X is given by
* n_a X_a + n_b X_b
* X = -----------------
* n_a + n_b
*
* <p>The std dev of combined sample S is n_a ( S_a^2 + (X_a - X)^2) + n_b(S_b^2 +
* (X_b - X)^2) S = ----------------------------------------------------- n_a +
* n_b
* The std dev of combined sample S is
* n_a ( S_a^2 + (X_a - X)^2) + n_b(S_b^2 + (X_b - X)^2)
* S = sqrt( ----------------------------------------------------- )
* n_a + n_b
*/
double averageTime = (n_a * X_a + n_b * X_b) / totalCalls;
double stdDevTime =
(n_a * (Math.pow(S_a, 2) + Math.pow(X_a - averageTime, 2))
+ n_b * (Math.pow(S_b, 2) + Math.pow(X_b - averageTime, 2)))
/ totalCalls;
Math.sqrt(
(n_a * (Math.pow(S_a, 2) + Math.pow(X_a - averageTime, 2))
+ n_b * (Math.pow(S_b, 2) + Math.pow(X_b - averageTime, 2)))
/ totalCalls);
previousQueryObj.put("total_time", totalTime);
previousQueryObj.put("calls", totalCalls);
previousQueryObj.put("rows", rows);
Expand Down

0 comments on commit de7969e

Please sign in to comment.