-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcost.go
63 lines (55 loc) · 1.84 KB
/
cost.go
1
2
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package joise
import (
"database/sql"
"fmt"
"log"
"github.com/lib/pq"
)
var (
minReadCost = 1000000.0
readSetCostSlope = 1253.19054300781
readSetCostIntercept = -9423326.99507381
readListCostSlope = 1661.93366983753
readListCostIntercept = 1007857.48225696
)
func readListCost(length int) float64 {
f := readListCostSlope*float64(length) + readListCostIntercept
if f < minReadCost {
f = minReadCost
}
return f / 1000000.0
}
func readSetCost(size int) float64 {
f := readSetCostSlope*float64(size) + readSetCostIntercept
if f < minReadCost {
f = minReadCost
}
return f / 1000000.0
}
func readSetCostReduction(size, truncation int) float64 {
return readSetCost(size) - readSetCost(size-truncation)
}
// resetCostFunctionParameters re-computes the slopes and intercepts of cost functions
func resetCostFunctionParameters(db *sql.DB, pgTableReadListCostSamples, pgTableReadSetCostSamples string) {
var slope, intercept float64
err := db.QueryRow(fmt.Sprintf(`
SELECT regr_slope(cost, frequency), regr_intercept(cost, frequency) from %s;`,
pq.QuoteIdentifier(pgTableReadListCostSamples))).Scan(&slope, &intercept)
if err != nil {
panic(err)
}
log.Printf("Reseting read list cost slope %.4f -> %.4f", readListCostSlope, slope)
log.Printf("Reseting read list cost intercept %.4f -> %.4f", readListCostIntercept, intercept)
readListCostSlope = slope
readListCostIntercept = intercept
err = db.QueryRow(fmt.Sprintf(`
SELECT regr_slope(cost, size), regr_intercept(cost, size) from %s;`,
pq.QuoteIdentifier(pgTableReadSetCostSamples))).Scan(&slope, &intercept)
if err != nil {
panic(err)
}
log.Printf("Reseting read set cost slope %.4f -> %.4f", readSetCostSlope, slope)
log.Printf("Reseting read set cost intercept %.4f -> %.4f", readSetCostIntercept, intercept)
readSetCostSlope = slope
readSetCostIntercept = intercept
}