Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark xmm #20

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions raw_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func Test_Syscall6(t *testing.T) {
}

func Test_LineAlloc(t *testing.T) {
userSize, num := unsafe.Sizeof(User{}), 1000000000
fmt.Println(heapRawMemoryBytes*8, unsafe.Sizeof(User{})*1000000000)
userSize, num := unsafe.Sizeof(User{}), 10000
fmt.Println(heapRawMemoryBytes*8, unsafe.Sizeof(User{})*uintptr(num))
size := int(round(uintptr(heapRawMemoryBytes*8), 4096))
addr := uintptr(sysReserve(size)) // 必须预留的多才可以 arena linearAlloc学习这个
prot, flags, fd, offset, length := syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_FIXED|syscall.MAP_PRIVATE, -1, 0, size
Expand Down
2 changes: 1 addition & 1 deletion span_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestSpanLock(t *testing.T) {

func Test_SanPool_Alloc(t *testing.T) {
f := &Factory{}
mm, err := f.CreateConcurrentHashMapMemory(0.6, 1)
mm, err := f.CreateMemory(0.6)
if err != nil {
panic(err)
}
Expand Down
19 changes: 1 addition & 18 deletions xmm.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type Factory struct {
sp *xSpanPool
}

// CreateMemory spanFact为负载因子,当span内存超过这个百分比阈值,就会扩容
func (s *Factory) CreateMemory(spanFact float32) (XMemory, error) {
if spanFact <= 0 {
return nil, NilError
Expand All @@ -159,24 +160,6 @@ func (s *Factory) CreateMemory(spanFact float32) (XMemory, error) {
return &mm{sp: sp, sa: sa, h: h}, nil
}

//NewXConcurrentHashMapSpanPool
func (s *Factory) CreateConcurrentHashMapMemory(spanFact float32, pageNumCoefficient uint8) (XMemory, error) {
if spanFact <= 0 {
return nil, NilError
}
h, err := newXHeap()
if err != nil {
return nil, err
}
sp, err := newXConcurrentHashMapSpanPool(h, spanFact, pageNumCoefficient)
if err != nil {
return nil, err
}
sa := newXStringAllocator(sp)
s.sp = sp
return &mm{sp: sp, sa: sa, h: h}, nil
}

func (s *Factory) PrintStatus() {
for index, u := range s.sp.inuse {
if u < 100 {
Expand Down
2 changes: 1 addition & 1 deletion xmm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func Test_NewUser(t *testing.T) {

func Test_FromInAddr(t *testing.T) {
f := &Factory{}
mm, err := f.CreateConcurrentHashMapMemory(0.6, 1)
mm, err := f.CreateMemory(0.6)
if err != nil {
t.Fatal(err)
}
Expand Down