Giter VIP home page Giter VIP logo

Comments (9)

cornelk avatar cornelk commented on May 18, 2024

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.

Zeymo avatar Zeymo commented on May 18, 2024

cool, thanks!

from hashmap.

Zeymo avatar Zeymo commented on May 18, 2024

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.

cornelk avatar cornelk commented on May 18, 2024

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.

Zeymo avatar Zeymo commented on May 18, 2024

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.

cornelk avatar cornelk commented on May 18, 2024

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.

Zeymo avatar Zeymo commented on May 18, 2024

close it , if have further questions I will reopen it :)

from hashmap.

cornelk avatar cornelk commented on May 18, 2024

I added a new GetOrInsert function for this usecase.

from hashmap.

Zeymo avatar Zeymo commented on May 18, 2024

cool!

from hashmap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.