Permalink
Browse files

Merge branch 'master' of github.com:ryandotsmith/wcld

  • Loading branch information...
2 parents 469e1b7 + fba1ee1 commit b9779b5f28eff62823e62773df33c17762e7b461 Ryan Smith (ace hacker) committed Mar 26, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 readme.md
View
@@ -25,6 +25,8 @@ quickly group our app's average response time grouped by hour:
$ heroku pg:psql
```
+### Avg
+
```sql
SELECT
date_trunc('hour', time) AS time_group,
@@ -51,6 +53,38 @@ WHERE
2012-02-14 03:00:00+00 | 00:00:00.073081
```
+### Percentile
+
+```sql
+SELECT
+ perctile,
+ avg(elapsed_time::interval)
+FROM (
+ SELECT
+ data -> 'elapsed_time' as elapsed_time,
+ ntile(100) over (order by (data -> 'elapsed_time')) as perctile
+ FROM
+ log_data
+ WHERE
+ data -> 'action' = 'find_prev_rec'
+ and
+ time > now() - '9 minutes'::interval
+ and
+ expired = false
+) x
+WHERE
+ perctile = 95
+GROUP BY perctile
+;
+```
+
+```
+ perctile | avg
+----------+-----------------
+ 95 | 00:00:00.008944
+(1 row)
+```
+
### Indicies
One possible indexing strategy:

0 comments on commit b9779b5

Please sign in to comment.