High CPU usage in dgraph v1.0.0 when I don't do any queries/mutations
Dgraph version:
Dgraph version : v1.0.0
Commit SHA-1 : 7a64f54b
Commit timestamp : 2017-12-18 15:04:40 +0530
Branch : HEAD
Dgraph linux binary: dgraph-linux-amd64-v1.0.0.tar.gz
OS: Manjaro (Based on Arch Linux. I consider it's the same as arch linux)
How do I run dgraph:
dgraph zero --port_offset -2000 -w ${db_path}/zw/ >> ${log_file_zero} 2>&1 &
sleep 10
dgraph server --memory_mb 1024 --zero localhost:5080 -p ${db_path}/p/ -w ${db_path}/w/ >> ${log_file_server} 2>&1 &
- Create the schema by following https://tour.dgraph.io/moredata/1/
- Load the dataset with
dgraph live -r 1million.rdf.gz --zero localhost:5080 - Shutdown and Restart dgraph zero and server to free up RAM.
- Apply the schema mutation at https://tour.dgraph.io/search/1/
After the above 4 steps, the CPU usage is high about 40% busy when I don't do anything. I tried to shutdown and restart the dgraph zero and server many times. The CPU usage is always high when idle. It's not high all the time. It follows some kind of patterns. The CPU usage is high for several minutes, low for several minutes and then high again.
This never happens in pre v1.0.0 versions such as v0.9.4, v0.9.2 etc...
BTW, when I shutdown the dgraph server properly with curl http://localhost:8080/admin/shutdown, I always see the following snippet:
goroutine 511 [running]:
github.com/dgraph-io/dgraph/vendor/github.com/dgraph-io/badger.(*DB).sendToWriteCh(0xc420444300, 0x0, 0x0, 0x0, 0x10, 0x10, 0xc43218e460)
/home/travis/gopath/src/github.com/dgraph-io/dgraph/vendor/github.com/dgraph-io/badger/db.go:609 +0x15f
github.com/dgraph-io/dgraph/vendor/github.com/dgraph-io/badger.(*DB).batchSet(0xc420444300, 0x0, 0x0, 0x0, 0x0, 0x10)
/home/travis/gopath/src/github.com/dgraph-io/dgraph/vendor/github.com/dgraph-io/badger/db.go:679 +0x4d
github.com/dgraph-io/dgraph/vendor/github.com/dgraph-io/badger.(*DB).purgeVersionsBelow(0xc420444300, 0xc43345d290, 0xc43218e460, 0x10, 0x10, 0x8, 0x0, 0x0)
/home/travis/gopath/src/github.com/dgraph-io/dgraph/vendor/github.com/dgraph-io/badger/db.go:931 +0x453
github.com/dgraph-io/dgraph/vendor/github.com/dgraph-io/badger.(*ManagedDB).PurgeVersionsBelow(0xc42014e138, 0xc43218e460, 0x10, 0x10, 0x8, 0x0, 0x0)
/home/travis/gopath/src/github.com/dgraph-io/dgraph/vendor/github.com/dgraph-io/badger/managed_db.go:79 +0x127
github.com/dgraph-io/dgraph/posting.periodicPurgeOldVersions.func1()
/home/travis/gopath/src/github.com/dgraph-io/dgraph/posting/lists.go:244 +0x2a2
github.com/dgraph-io/dgraph/posting.periodicPurgeOldVersions()
/home/travis/gopath/src/github.com/dgraph-io/dgraph/posting/lists.go:254 +0x40
created by github.com/dgraph-io/dgraph/posting.Init
/home/travis/gopath/src/github.com/dgraph-io/dgraph/posting/lists.go:211 +0xe1
I am not sure if this is related or not. This never appears before version 1.0.
One more werid part in version 1.0.0 is if I remove sleep 10 in the above script when I start dgraph, that means dgraph zero and server start at the same time. I can see about 9000 lines of:
2017/12/19 15:39:27 groups.go:673: Error in oracle delta stream. Error: rpc error: code = Unknown desc = Node is no longer leader.
in the dgraph server log (stdout).
I don't think this is expected and never see such behavior before version 1.0. I am not sure if I should open another bug for this or not.
I attached three CPU profiles:
pprof.dgraph.samples.cpu.001.pb.gz
@sgon00
2017/12/19 15:39:27 groups.go:673: Error in oracle delta stream. Error: rpc error: code = Unknown desc = Node is no longer leader. error is expected when there's no active leader of group zero. During restart it takes some time for zero to become leader and hence dgraph servers try to find a zero which is leader.
I have added sleeps between retries now so you shouldn't see this.
You didn't see this issue before because of bug which was fixed in v1.0, but since there was only one zero and it eventually became leader so the system worked fine at the end.
The panic is due to some background goroutine, i will make a fix to stop it during clean shutdown. But it doesn't affect anything.
@janardhan1993 thanks a lot for the quick reply and investigation. About 9000 error messages in the log within a second made me feel bad. :) What about the CPU usage problem? I hope that can be fixed soon. It's burning my laptop. I can not use dgraph if it uses too much CPU constantly when I don't do anything to it. Thanks a lot.
I have same problem with docker compose environment on my desktop.
It began when I imported about 14M data-set.
CPU usage goes up after I make first query on DB.
We are working on it, will fix it in next release.
Have the same problem with 1.1
Every few minutes the dgraph process CPU utilization get to around 170% for a minute or so.
The machine is: Intel i7-4790k With SSD & 16GB RAM + the 1mil DB from the tutorial
From the machine/OS (fedora 27) perspective other DBs like PostgreSQL & ElasticSearch work as expected. Let me know if you need more info
@mbn18 Can you please share the cpu profile when it goes high.
Most probably it's related to purging older versions which happens in background. We changed the way purge works in badger to make it efficient and fast. Will vendor in the change in dgraph after some testing.
@janardhan1993 , No problem. Any doc on how to profile the CPU?
https://docs.dgraph.io/howto/#retrieving-debug-information @mbn18
The CPU profile is attached. Its started few sec before the load start and finish few sec after the load get down.
I also noticed that the load/offload takes 30 seconds.
Fixed in master, @mbn18 Can you please try using master.
@janardhan1993 , By master you mean the latest docker that is tagged as master?
Yeah dgraph:master, please pull again it has been updated just now
I'm having the same cpu issue, I've tried the latest dgraph/dgraph from docker and the same cpu issue still spiking up, any update?
@samhuss
docker pull dgraph/dgraph:master
@janardhan1993
Something is broken or maybe changed since 1.0.2
docker run --rm -it -p 8081:8081 -p 8080:8080 -p 9080:9080 -v /home/miki/Projects/Epoch/dgraph/db:/dgraph --name dgraph dgraph/dgraph:master dgraph zero --port_offset=-2000
Setting up grpc listener at: 0.0.0.0:3080
Setting up http listener at: 0.0.0.0:4080
2018/02/01 11:53:12 node.go:258: Group 0 found 0 entries
2018/02/01 11:53:12 raft.go:567: INFO: 1 became follower at term 0
2018/02/01 11:53:12 raft.go:315: INFO: newRaft 1 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2018/02/01 11:53:12 raft.go:567: INFO: 1 became follower at term 1
Running Dgraph zero...
2018/02/01 11:53:12 node.go:127: Setting conf state to nodes:1
2018/02/01 11:53:16 raft.go:749: INFO: 1 is starting a new election at term 1
2018/02/01 11:53:16 raft.go:580: INFO: 1 became candidate at term 2
2018/02/01 11:53:16 raft.go:664: INFO: 1 received MsgVoteResp from 1 at term 2
2018/02/01 11:53:16 raft.go:621: INFO: 1 became leader at term 2
2018/02/01 11:53:16 node.go:301: INFO: raft.node: 1 elected leader 1 at term 2
docker exec -it dgraph dgraph server --bindall=true --memory_mb 2048 --zero localhost:5080
2018/02/01 11:54:21 groups.go:86: Current Raft Id: 0
2018/02/01 11:54:21 gRPC server started. Listening on port 9080
2018/02/01 11:54:21 HTTP server started. Listening on port 8080
2018/02/01 11:54:21 worker.go:99: Worker listening at address: [::]:7080
2018/02/01 11:54:21 pool.go:168: Echo error from localhost:5080. Err: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:21 pool.go:118: == CONNECT ==> Setting localhost:5080
2018/02/01 11:54:21 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:21 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:22 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:22 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:22 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:23 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:25 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:28 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:31 pool.go:168: Echo error from localhost:5080. Err: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:34 groups.go:102: Error while connecting with group zero: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:41 pool.go:168: Echo error from localhost:5080. Err: rpc error: code = Unavailable desc = all SubConns are in TransientFailure
2018/02/01 11:54:47 Unable to join cluster via dgraphzero
github.com/dgraph-io/dgraph/x.Fatalf
/home/pawan/go/src/github.com/dgraph-io/dgraph/x/error.go:103
github.com/dgraph-io/dgraph/worker.StartRaftNodes
/home/pawan/go/src/github.com/dgraph-io/dgraph/worker/groups.go:107
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:2337
@mbn18 Thanks, that worked
After pulling the latest from master, still having the same cpu issue and now even worse. The cpu runs in 200+ without executing any queries in the browser
@mbn18, the default port for zero has been changed, it now runs at 3080 instead of 5080, so please use -zero="localhost:3080"
@samhuss DId you take the cpu profile when the cpu usage was high, i don't see anything except http requests in the profile, can you please send a png if possible.
@janardhan1993 unfortunately I had to figure out the new ports myself, I removed "--port_offset" option from the zero command to keep the old ports as is 5080,6080
running dgraph/dgraph:master on empty folder is not working, gives the following errors, as a work around I imported data using :latest then running :master on the same folder, which also didn't work properly
I'm using 2 docker-compose files for "latest" and "master" with the same volume of data, I'm not sure whether "master" can read the same data generated by "latest" or not as currently "master" doesn't run on "latest" data
server_1 | 2018/02/03 11:33:38 pool.go:118: == CONNECT ==> Setting localhost:5080 server_1 | 2018/02/03 11:33:38 draft.go:140: Node ID: 1 with GroupID: 1 server_1 | 2018/02/03 11:33:38 node.go:258: Group 1 found 0 entries server_1 | 2018/02/03 11:33:38 draft.go:672: New Node for group: 1 server_1 | 2018/02/03 11:33:38 raft.go:567: INFO: 1 became follower at term 0 server_1 | Error while proposing initial schema: Tablet isn't being served by this instance. server_1 | 2018/02/03 11:33:38 raft.go:315: INFO: newRaft 1 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0] server_1 | 2018/02/03 11:33:38 raft.go:567: INFO: 1 became follower at term 1 server_1 | 2018/02/03 11:33:38 groups.go:296: Asking if I can serve tablet for: predicate server_1 | 2018/02/03 11:33:38 groups.go:434: WARNING: We don't have address of any dgraphzero server. server_1 | 2018/02/03 11:33:38 groups.go:653: WARNING: We don't have address of any dgraphzero server. server_1 | 2018/02/03 11:33:38 node.go:127: Setting conf state to nodes:1 server_1 | 2018/02/03 11:33:38 raft.go:749: INFO: 1 is starting a new election at term 1 server_1 | 2018/02/03 11:33:38 raft.go:580: INFO: 1 became candidate at term 2 server_1 | 2018/02/03 11:33:38 raft.go:664: INFO: 1 received MsgVoteResp from 1 at term 2 server_1 | 2018/02/03 11:33:38 raft.go:621: INFO: 1 became leader at term 2 server_1 | 2018/02/03 11:33:38 node.go:301: INFO: raft.node: 1 elected leader 1 at term 2 server_1 | Error while proposing initial schema: Tablet isn't being served by this instance. server_1 | 2018/02/03 11:33:38 groups.go:296: Asking if I can serve tablet for: predicate server_1 | 2018/02/03 11:33:38 groups.go:296: Asking if I can serve tablet for: predicate server_1 | Error while proposing initial schema: Tablet isn't being served by this instance. server_1 | Error while proposing initial schema: Tablet isn't being served by this instance. server_1 | 2018/02/03 11:33:38 groups.go:296: Asking if I can serve tablet for: predicate server_1 | Error while proposing initial schema: Tablet isn't being served by this instance. server_1 | 2018/02/03 11:33:39 groups.go:296: Asking if I can serve tablet for: predicate server_1 | 2018/02/03 11:33:39 groups.go:296: Asking if I can serve tablet for: predicate server_1 | Error while proposing initial schema: Tablet isn't being served by this instance. server_1 | 2018/02/03 11:33:39 groups.go:296: Asking if I can serve tablet for: predicate server_1 | Error while proposing initial schema: Tablet isn't being served by this instance. server_1 | 2018/02/03 11:33:39 groups.go:296: Asking if I can serve tablet for: ...... etc......
Could you share the docker_compose.yml file which uses the master Docker image? I don't see zero running from the logs that is why you get the Error while proposing initial schema.
I suspect there is something wrong with the config because of which Zero doesn't run. dgraph/dgraph:master should work with the data from the previous release.