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

Use uint64 intead of uint32 #236

Merged
merged 10 commits into from
Nov 4, 2020
Merged

Conversation

janisz
Copy link
Collaborator

@janisz janisz commented Aug 21, 2020

There are posibility we run into a problem of int32 overflow.
To prevent this let's use uint64 everywhere.

s.hashmap[hashedKey] = uint32(index)

Fixes: #148

@siennathesane
Copy link
Collaborator

I like this, but we should document that this change breaks 32-bit compatibility (assuming it existed already), and this should likely be a new version.

@siennathesane siennathesane added this to the 3.0.0 milestone Aug 31, 2020
@siennathesane
Copy link
Collaborator

@cristaloleg do you want this to be a part of 3.0 since it breaks 32-bit compatibility or just cut a new release as normal?

@cristaloleg
Copy link
Collaborator

Well, breaking 32bit compatibility in patch/minor version is a bad thing. Better to postpone till 3.0 :(

@siennathesane
Copy link
Collaborator

@janisz if you can rebase against the versions/v3-prep branch, then edit the PR to point to that branch, we can get this merged in.

@janisz
Copy link
Collaborator Author

janisz commented Oct 7, 2020

@mxplusb Done

@janisz janisz force-pushed the fix_148 branch 2 times, most recently from 6ec47a5 to e861020 Compare October 7, 2020 19:05
@janisz
Copy link
Collaborator Author

janisz commented Oct 8, 2020

Interesting, race checker adds more memory

bigcache git:(fix_148) ✗ go test
2020/10/08 22:24:22 Allocated new queue in 492ns; Capacity: 88 
2020/10/08 22:24:22 Allocated new queue in 5.826µs; Capacity: 256046 
2020/10/08 22:24:22 Allocated new queue in 122.952µs; Capacity: 512092 
2020/10/08 22:24:22 Allocated new queue in 318.934µs; Capacity: 1024184 
2020/10/08 22:24:23 Allocated new queue in 267.441µs; Capacity: 585000 
2020/10/08 22:24:23 Allocated new queue in 294.733µs; Capacity: 1170000 
PASS
ok  	github.com/allegro/bigcache/v3	14.906s
➜  bigcache git:(fix_148) ✗ go test -race
signal: killed
FAIL	github.com/allegro/bigcache/v3	19.155s
bigcache git:(fix_148) ✗ dmesg
[44698.559338] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice,task=bigcache.test,pid=26385,uid=1000
[44698.559368] Out of memory: Killed process 26385 (bigcache.test) total-vm:31216124kB, anon-rss:19200356kB, file-rss:0kB, shmem-rss:3452kB, UID:1000 pgtables:39016kB oom_score_adj:0
[44698.973775] oom_reaper: reaped process 26385 (bigcache.test), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB
bigcache git:(fix_148) ✗ go version
go version go1.15.2 linux/amd64

@janisz
Copy link
Collaborator Author

janisz commented Oct 8, 2020

bigcache git:(fix_148) ✗ go test -race -c -o test_race github.com/allegro/bigcache/v3bigcache git:(fix_148) ✗ /usr/bin/time -v ./test_race                                 
Command terminated by signal 9
	Command being timed: "./test_race"
	User time (seconds): 19.79
	System time (seconds): 9.03
	Percent of CPU this job got: 151%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:18.97
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 18998948
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 130
	Minor (reclaiming a frame) page faults: 8179180
	Voluntary context switches: 2791
	Involuntary context switches: 558
	Swaps: 0
	File system inputs: 27864
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0
➜  bigcache git:(fix_148) ✗ go test -c -o test github.com/allegro/bigcache/v3  
➜  bigcache git:(fix_148) ✗ /usr/bin/time -v ./test                           
PASS
	Command being timed: "./test"
	User time (seconds): 19.65
	System time (seconds): 3.31
	Percent of CPU this job got: 146%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:15.71
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 13417992
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 1020072
	Voluntary context switches: 324544
	Involuntary context switches: 640
	Swaps: 0
	File system inputs: 0
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

@codecov-io
Copy link

codecov-io commented Oct 8, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@9949a06). Click here to learn what that means.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #236   +/-   ##
=========================================
  Coverage          ?   87.18%           
=========================================
  Files             ?       15           
  Lines             ?      640           
  Branches          ?        0           
=========================================
  Hits              ?      558           
  Misses            ?       69           
  Partials          ?       13           
Impacted Files Coverage Δ
server/server.go 29.03% <ø> (ø)
queue/bytes_queue.go 92.59% <100.00%> (ø)
shard.go 84.93% <100.00%> (ø)
iterator.go 88.67% <0.00%> (ø)
bigcache.go 98.79% <0.00%> (ø)
fnv.go 100.00% <0.00%> (ø)
utils.go 62.50% <0.00%> (ø)
bytes.go 100.00% <0.00%> (ø)
logger.go 100.00% <0.00%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9949a06...6a48d10. Read the comment docs.

@janisz
Copy link
Collaborator Author

janisz commented Oct 8, 2020

Well, breaking 32bit compatibility in patch/minor version is a bad thing. Better to postpone till 3.0 :(

I'm not sure if this breaks compatibility. API is the same so on 32bits it will work as before

janisz and others added 3 commits October 9, 2020 06:32
Signed-off-by: Mike Lloyd <[email protected]>
There are posibility we run into a problem of int32 overflow.
To prevent this let's use uint64 everywhere.

https://github.com/allegro/bigcache/blob/21e5ca5c3d539f94e8dc563350acd97c5400154f/shard.go#L138

Fixes: allegro#148
@janisz
Copy link
Collaborator Author

janisz commented Oct 12, 2020

I removed 1.13 since it's failing. I need to debug why

@janisz
Copy link
Collaborator Author

janisz commented Oct 12, 2020

It's passing on my machine?

➜  bigcache git:(fix_148) ✗ go test -short -race            
2020/10/12 19:00:06 Allocated new queue in 51.32µs; Capacity: 256046 
2020/10/12 19:00:06 Allocated new queue in 1.668359ms; Capacity: 512092 
2020/10/12 19:00:06 Allocated new queue in 1.031µs; Capacity: 88 
2020/10/12 19:00:06 Allocated new queue in 3.652714ms; Capacity: 1024184 
2020/10/12 19:00:06 Allocated new queue in 2.43308ms; Capacity: 585000 
2020/10/12 19:00:06 Allocated new queue in 5.981636ms; Capacity: 1170000 
PASS
ok  	github.com/allegro/bigcache/v3	42.315s
➜  bigcache git:(fix_148) ✗ go version
go version go1.13.15 linux/amd64

@janisz
Copy link
Collaborator Author

janisz commented Oct 13, 2020

@cristaloleg @mxplusb PTAL

cristaloleg
cristaloleg previously approved these changes Oct 14, 2020
@@ -42,7 +42,7 @@ jobs:
run: |
go test -race -count=1 -coverprofile=queue.coverprofile ./queue
go test -race -count=1 -coverprofile=server.coverprofile ./server
go test -race -count=1 -coverprofile=main.coverprofile
go test -race -count=1 -coverprofile=main.coverprofile -short
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait a sec, why short?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siennathesane
Copy link
Collaborator

@cristaloleg It looks like the 1.13.x build requirement is blocking the merge, can you remove it?

* Add Benchmark for append

* Optimize Append and halve byte copies

* Optimize Append by reducing allocs

* Optimize Append by reducing allocs

* Reduces allocs from test construct

Co-authored-by: Fabian Gärtner <[email protected]>
@janisz
Copy link
Collaborator Author

janisz commented Oct 31, 2020

@cristaloleg PTAL

@siennathesane siennathesane changed the base branch from master to versions/v3-prep November 4, 2020 01:19
@siennathesane
Copy link
Collaborator

I'm merging this into the v3 base so we can close out the work item so it's in 3.0.

@siennathesane siennathesane merged commit 64eb605 into allegro:versions/v3-prep Nov 4, 2020
siennathesane pushed a commit that referenced this pull request Nov 4, 2020
* Fix iterator styling issues (#247)

Issues reported in #246

* fix #160 (#246)

* Update to latest golang (#248)

Co-authored-by: Oleg Kovalov <[email protected]>

* inital prep for v3.

Signed-off-by: Mike Lloyd <[email protected]>

* Use uint64 intead of uint32

There are posibility we run into a problem of int32 overflow.
To prevent this let's use uint64 everywhere.

https://github.com/allegro/bigcache/blob/21e5ca5c3d539f94e8dc563350acd97c5400154f/shard.go#L138

Fixes: #148

* Fix CI

* Do not run on 1.13

* Do not run long test

* Optimze append (#249)

* Add Benchmark for append

* Optimize Append and halve byte copies

* Optimize Append by reducing allocs

* Optimize Append by reducing allocs

* Reduces allocs from test construct

Co-authored-by: Fabian Gärtner <[email protected]>

Co-authored-by: S@P <[email protected]>
Co-authored-by: Oleg Kovalov <[email protected]>
Co-authored-by: Mike Lloyd <[email protected]>
Co-authored-by: Fabianexe <[email protected]>
Co-authored-by: Fabian Gärtner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic out of range in bytes queue
6 participants