Comments (9)
I added this good example of a use case as a test now: https://github.com/cornelk/hashmap/blob/master/hashmap_test.go#L270
from hashmap.
cool, thanks!
from hashmap.
when I use this map in production env, this occur a high cpu behavier amlost 100%, we have thousands of api online and I init map as 1024 size ,info is below
It will always has a gorutine in grow
# 0x66f037 mwcs/framework/datastructures/maps.(*HashMap).grow+0x67 /src/src/mwcs/framework/datastructures/maps/hashmap.go:266
# 0x66eba1 mwcs/framework/datastructures/maps.(*HashMap).insertListElement+0x131 /src/src/mwcs/framework/datastructures/maps/hashmap.go:190
# 0x66e5e1 mwcs/framework/datastructures/maps.(*HashMap).Insert+0xd1 /src/src/mwcs/framework/datastructures/maps/hashmap.go:121
hashmap.go:190 mapping
https://github.com/cornelk/hashmap/blob/master/hashmap.go#L174
hashmap.go:266 mapping
https://github.com/cornelk/hashmap/blob/master/hashmap.go#L255
----------------------------------------------------------+-------------
flat flat% sum% cum cum% calls calls% + context
----------------------------------------------------------+-------------
99.87s 100% | mwcs/framework/datastructures/maps.(*List).Add
92.89s 91.32% 91.32% 99.87s 98.18% | mwcs/framework/datastructures/maps.(*List).search
6.98s 100% | mwcs/framework/datastructures/maps.(*ListElement).Next
----------------------------------------------------------+-------------
flat flat% sum% cum cum%
92.89s 91.32% 91.32% 99.87s 98.18% mwcs/framework/datastructures/maps.(*List).search
I use hashmap as
if flag&DEBUG_FLAG > 0 {
hit = 1
sampleRate = 1
} else {
url := stream.Stream().HttpPath()
for {
val, ok := l.sampling.GetStringKey(url)
if !ok {
c := uint32(1)
if !l.sampling.Insert(url, unsafe.Pointer(&c)) {
continue
}
hit = 1
break
}
c := (*uint32)(val)
new := atomic.AddUint32(c, 1)
if new&(l.sampleRate-1) == 0 {
hit = 1
}
break
}
}
from hashmap.
This hashmap is optimized for fast reads, writes are currently not really optimized. To speed it up you should initialize the map with a larger size or even better initialize all keys with counter 0 on startup.
from hashmap.
yeah,I initialize size as 1024 already . Info above since element too much and use up cpu ? or t there is competition ( maybe lock occupy?) hidden danger cause cpu 100%?
from hashmap.
can you initialize the hashmap with all keys with counter 0 on startup? please create a test so that i can replicate the behavior.
from hashmap.
close it , if have further questions I will reopen it :)
from hashmap.
I added a new GetOrInsert function for this usecase.
from hashmap.
cool!
from hashmap.
Related Issues (20)
- Having break statement while iterating causes goroutine leak HOT 1
- .Get on absent key fatalpanics HOT 1
- the speed for set is really really really low HOT 5
- panic: unsupported key type *foo HOT 3
- Lost writes on table growth HOT 4
- Getting this error when there are many go routines trying to access the value HOT 1
- Question: is possible the values in `left` and `right` are change when inserting a new element? HOT 7
- Panic with Mac M1 and Delve debuger HOT 1
- Thank you HOT 1
- minor version updates break the API HOT 1
- Hang when using GetOrInsert and DEL HOT 3
- Support compound keys
- invalid recursive type atomic.Pointer HOT 3
- 1.19.4 HOT 2
- Unexpected behaviors under large number of data
- [BUG] - Doesn't seem to be thread safe
- i changed some case with grow and the write speed is more quickly than others HOT 1
- Very slow compared to map? HOT 1
- list add method is not correct
- Is it safe to call Del or Set during iterating via Range? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashmap.