-
Notifications
You must be signed in to change notification settings - Fork 264
/
main.go
110 lines (100 loc) · 2.74 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"os"
"runtime/pprof"
"sync"
"time"
"github.com/matrixorigin/matrixone/pkg/logutil"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/db"
"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils/config"
"github.com/panjf2000/ants/v2"
)
var sampleDir = "/tmp/sample1"
var dbName = "db"
var cpuprofile = "/tmp/sample1/cpuprofile"
var memprofile = "/tmp/sample1/memprofile"
func init() {
os.RemoveAll(sampleDir)
}
func startProfile() {
f, _ := os.Create(cpuprofile)
_ = pprof.StartCPUProfile(f)
}
func stopProfile() {
pprof.StopCPUProfile()
memf, _ := os.Create(memprofile)
defer memf.Close()
_ = pprof.Lookup("heap").WriteTo(memf, 0)
}
func main() {
ctx := context.Background()
opts := config.WithOpts(nil, 1)
tae, _ := db.Open(ctx, sampleDir, opts)
defer tae.Close()
schema := catalog.MockSchemaAll(10, 3)
schema.BlockMaxRows = 20
schema.ObjectMaxBlocks = 2
batchCnt := uint32(1)
batchRows := int(schema.BlockMaxRows * 1 / 20 * batchCnt)
{
txn, _ := tae.StartTxn(nil)
db, _ := txn.CreateDatabase(dbName, "", "")
_, _ = db.CreateRelation(schema)
if err := txn.Commit(context.Background()); err != nil {
panic(err)
}
}
bat := catalog.MockBatch(schema, batchRows)
bats := bat.Split(int(batchCnt))
var wg sync.WaitGroup
doAppend := func(b *containers.Batch) func() {
return func() {
defer wg.Done()
txn, _ := tae.StartTxn(nil)
db, err := txn.GetDatabase(dbName)
if err != nil {
panic(err)
}
rel, err := db.GetRelationByName(schema.Name)
if err != nil {
panic(err)
}
if err := rel.Append(context.Background(), b); err != nil {
panic(err)
}
if err := txn.Commit(context.Background()); err != nil {
panic(err)
}
}
}
p, _ := ants.NewPool(200)
now := time.Now()
startProfile()
for _, b := range bats {
wg.Add(1)
_ = p.Submit(doAppend(b))
}
wg.Wait()
stopProfile()
logutil.Infof("Append takes: %s", time.Since(now))
waitTime := time.Millisecond * time.Duration(batchCnt/200+1) * 300
for i := 0; i < 5; i++ {
time.Sleep(waitTime)
}
}