Skip to content

Commit

Permalink
Merge pull request #475 from metrico/micro_gc
Browse files Browse the repository at this point in the history
Micro gc
  • Loading branch information
akvlad authored Mar 15, 2024
2 parents 9d5d9cd + 9139b44 commit bc7338a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
40 changes: 17 additions & 23 deletions wasm_parts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import (
"wasm_parts/types"
)

//go:linkname get sync.(*Pool).Get
func get(p *sync.Pool) any {
panic("GET POOL")
}

var maxSamples = 5000000

type ctx struct {
Expand Down Expand Up @@ -445,11 +440,12 @@ type TestSeries struct {
data []byte
stepMs int64

labels labels.Labels
tsMs int64
generatedMs int64
val float64
i int
labels labels.Labels
tsMs int64
val float64
i int

state int
}

func (t *TestSeries) reset() {
Expand All @@ -462,23 +458,21 @@ func (t *TestSeries) reset() {

func (t *TestSeries) Next() bool {
if t.i*16 >= len(t.data) {
if t.generatedMs == 0 {
t.tsMs += t.stepMs
t.generatedMs += t.stepMs
return true
}
return false
}
ts := *(*int64)(unsafe.Pointer(&t.data[t.i*16]))
if ts-t.tsMs > t.stepMs && t.generatedMs < 300000 {
if t.state == 1 {
t.tsMs += t.stepMs
t.generatedMs += t.stepMs
return true
if t.tsMs >= ts {
t.state = 0
}
}
if t.state == 0 {
t.tsMs = ts
t.val = *(*float64)(unsafe.Pointer(&t.data[t.i*16+8]))
t.i++
t.state = 1
}
t.tsMs = ts
t.generatedMs = 0
t.val = *(*float64)(unsafe.Pointer(&t.data[t.i*16+8]))
t.i++
return true
}

Expand All @@ -496,7 +490,7 @@ func (t *TestSeries) Seek(tmMS int64) bool {
if t.i < 0 {
t.i = 0
}
t.tsMs = tmMS
t.tsMs = ms
t.val = *(*float64)(unsafe.Pointer(&t.data[t.i*16+8]))
t.i++
return true
Expand Down
10 changes: 0 additions & 10 deletions wasm_parts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ const getWasm = (() => {
const _Go = Go
var go = new _Go();
let wasm = null
let cnt = 0
let run = false
let int
async function init () {
go = new _Go();
run = true
const _wasm = await WebAssembly.instantiate(
gunzipSync(fs.readFileSync(WASM_URL)), go.importObject)
int && clearInterval(int)
int = setInterval(() => {
console.log(`WASM SIZE: ${Math.floor(wasm.exports.memory.buffer.byteLength / 1024 / 1024)} MB`)
}, 5000)
go.run(_wasm.instance)
wasm = _wasm.instance
wasm.exports.setMaxSamples(process.env.ADVANCED_PROMETHEUS_MAX_SAMPLES || 5000000)
Expand All @@ -41,8 +33,6 @@ const getWasm = (() => {
}]
})
)
cnt = 0
run = false
}
init()
return () => {
Expand Down
Binary file modified wasm_parts/main.wasm.gz
Binary file not shown.

0 comments on commit bc7338a

Please sign in to comment.