cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

stability: "GO in use" and "GO Sys" is too high

Open a6802739 opened this issue 10 years ago • 21 comments

here is my table's schema info, create table FC_word( IdeaId int, UnitId int, PlanId int, UserId int,
Iflag int, Ilong int, IdeaStat1 int, IdeaStat2 int, IdeaStat3 int, IdeaStat4 int, IdeaStat5 int, IdeaStat6 int, Touch int,
ModUid int, ModTime timestamp, Isdel int, ChkUid int,
ChkTime timestamp,
RsnId int,
Reason varchar(256), DeviceOpt int, Temperature int );

here is my insert sql: INSERT INTO fc_word VALUES (4199338396,807952347,20737795,6819880,1,1,4,0,0,4,0,0,7,6819880,'2015-03-27 14:28:43'::timestamp,0,NULL,'2015-03-27 14:34:13'::timestamp,32768,NULL,0,0), (4199338399,807952350,20737795,6819880,1,1,4,0,0,4,0,0,7,6819880,'2015-03-27 14:28:43'::timestamp,0,NULL,'2015-03-27 14:34:13'::timestamp,32768,NULL,0,3);

I insert 200 values like above in a insert statement. after I write about 200 million rows, the memory usage is like behind,  56afad813a9dff294da06902adcdb114

the QPS is like this:  b9cc84959efca5b04875aaabd3585e32

the memory usage seems too high. the QPS seems too low.

a6802739 avatar May 17 '16 10:05 a6802739

@tamird Can we make a load generator for this schema and try to reproduce the problem? Or are we seeing similar problems in our beta cluster tests?

petermattis avatar May 17 '16 23:05 petermattis

We have not been seeing similar problems. Sometimes the "go in use" value will spike quickly to many gigs and kill the process, but when the cluster is stable "go in use" is around 100MB and "go sys" is around 400MB.

Can you download http://host:port/debug/pprof/heap?debug=1 from one of these nodes and attach it here (and tell us which binary version you're running)?

bdarnell avatar May 18 '16 15:05 bdarnell

@bdarnell the binary version I use is beta-20160512. how can I get http://host:port/debug/pprof/heap?debug=1, should I add some code in main function?

a6802739 avatar May 19 '16 02:05 a6802739

http://host:port refers to the cockroach server's http port (8080 by default). So you could do curl http://localhost:8080/debug/pprof/heap?debug=1 > heap.profile

bdarnell avatar May 19 '16 14:05 bdarnell

here is my profile. heap.profile.zip

a6802739 avatar May 20 '16 03:05 a6802739

According to that heap profile, Go was only using 81MB. Was this profile taken at a time when "go in use" was reporting several GB? (you can generate this report yourself with go tool pprof ./cockroach heap.profile, then type top at the command prompt)

(pprof) top
73.52MB of 81.06MB total (90.70%)
Dropped 994 nodes (cum <= 0.41MB)
Showing top 10 nodes out of 127 (cum >= 1.03MB)
      flat  flat%   sum%        cum   cum%
   33.50MB 41.33% 41.33%    34.50MB 42.56%  github.com/cockroachdb/cockroach/sql/parser.(*scanner).scanNumber
      13MB 16.04% 57.37%    20.50MB 25.29%  github.com/cockroachdb/cockroach/storage.(*TimestampCache).Add.func1
      12MB 14.81% 72.18%    47.51MB 58.60%  github.com/cockroachdb/cockroach/sql/parser.(*sqlParserImpl).Parse
    7.50MB  9.25% 81.43%     7.50MB  9.25%  github.com/cockroachdb/cockroach/util/interval.(*Node).insert
    2.06MB  2.55% 83.97%     2.06MB  2.55%  github.com/cockroachdb/cockroach/sql/pgwire.(*readBuffer).readUntypedMsg
    1.13MB  1.40% 85.37%     1.13MB  1.40%  github.com/cockroachdb/cockroach/client.(*Batch).appendReqs
    1.10MB  1.35% 86.72%     2.81MB  3.46%  github.com/cockroachdb/cockroach/client.(*Txn).send
    1.10MB  1.35% 88.07%     3.90MB  4.81%  github.com/cockroachdb/cockroach/client.sendAndFill
    1.10MB  1.35% 89.42%     1.10MB  1.35%  github.com/cockroachdb/cockroach/kv.truncate
    1.03MB  1.27% 90.70%     1.03MB  1.27%  github.com/codahale/hdrhistogram.New

It looks like your queries may be very large; try inserting fewer rows at a time. Other than that, there's nothing unusual in this profile.

bdarnell avatar May 21 '16 15:05 bdarnell

@bdarnell thanks。I will try it again.

a6802739 avatar May 23 '16 03:05 a6802739

this photo is a new runtime memory stats. 606d71905fd63164214bba904417c961

here is the heap stats:

[email protected]:~$ go tool pprof http://localhost:8080/debug/pprof/heap
Fetching profile from http://localhost:8080/debug/pprof/heap
Saved profile in /root/pprof/pprof.localhost:8080.inuse_objects.inuse_space.010.pb.gz
Entering interactive mode (type "help" for commands)
(pprof) top
214.18MB of 225.91MB total (94.81%)
Dropped 1084 nodes (cum <= 1.13MB)
Showing top 10 nodes out of 106 (cum >= 1.50MB)
      flat  flat%   sum%        cum   cum%
   99.01MB 43.83% 43.83%   107.01MB 47.37%  github.com/cockroachdb/cockroach/sql/parser.(*scanner).scanNumber
   49.01MB 21.70% 65.52%   159.02MB 70.39%  github.com/cockroachdb/cockroach/sql/parser.(*sqlParserImpl).Parse
   14.50MB  6.42% 71.94%       26MB 11.51%  github.com/cockroachdb/cockroach/storage.(*TimestampCache).Add.func1
   13.84MB  6.12% 78.07%    13.84MB  6.12%  github.com/cockroachdb/cockroach/storage.(*CommandQueue).add
   11.50MB  5.09% 83.16%    11.50MB  5.09%  github.com/cockroachdb/cockroach/util/interval.(*Node).insert
   10.81MB  4.79% 87.95%    10.81MB  4.79%  github.com/cockroachdb/cockroach/sql/pgwire.(*readBuffer).readUntypedMsg
       8MB  3.54% 91.49%        8MB  3.54%  go/constant.MakeFromLiteral
       3MB  1.33% 92.81%        3MB  1.33%  github.com/cockroachdb/cockroach/sql/parser.(*scanner).scanString
       3MB  1.33% 94.14%        3MB  1.33%  github.com/cockroachdb/cockroach/roachpb.(*Span).Unmarshal
    1.50MB  0.67% 94.81%     1.50MB  0.67%  github.com/cockroachdb/cockroach/storage.(*CommandQueue).getWait
(pprof)

a6802739 avatar May 23 '16 12:05 a6802739

the photo is not clear. 13e8e2036c43c1865fa67c94028be6c2

a6802739 avatar May 23 '16 13:05 a6802739

after running a log time, my cluster is stable with that stat.

a6802739 avatar May 23 '16 13:05 a6802739

If it's stable, then that looks fairly normal - the Go memory in use is reasonable relative to the total process size. It could be improved (that's a lot of memory to spend on parsed numbers), but I'm not seeing that obviously needs fixing.

bdarnell avatar May 24 '16 04:05 bdarnell

@bdarnell today I execute a sql like this 'create index USER_ID on fc_word(UserId);' . the memory usage is a little too high.

3363e78c25cbf9089258df1127d85fb0

the heap status is,

(pprof) top
351.42MB of 368.60MB total (95.34%)
Dropped 1319 nodes (cum <= 1.84MB)
Showing top 10 nodes out of 92 (cum >= 3.01MB)
      flat  flat%   sum%        cum   cum%
  159.51MB 43.28% 43.28%   167.51MB 45.45%  github.com/cockroachdb/cockroach/sql/parser.(*scanner).scanNumber
   70.52MB 19.13% 62.41%   246.04MB 66.75%  github.com/cockroachdb/cockroach/sql/parser.(*sqlParserImpl).Parse
   41.01MB 11.12% 73.53%    72.51MB 19.67%  github.com/cockroachdb/cockroach/storage.(*TimestampCache).Add.func1
   31.50MB  8.55% 82.08%    31.50MB  8.55%  github.com/cockroachdb/cockroach/util/interval.(*Node).insert
   11.83MB  3.21% 85.29%    11.83MB  3.21%  github.com/cockroachdb/cockroach/sql/pgwire.(*readBuffer).readUntypedMsg
   11.04MB  2.99% 88.28%    11.04MB  2.99%  github.com/cockroachdb/cockroach/storage.(*CommandQueue).add
       8MB  2.17% 90.45%        8MB  2.17%  github.com/cockroachdb/cockroach/sql/parser.(*scanner).scanString
       8MB  2.17% 92.62%        8MB  2.17%  go/constant.MakeFromLiteral
       7MB  1.90% 94.52%        7MB  1.90%  github.com/cockroachdb/cockroach/roachpb.(*Span).Unmarshal
    3.01MB  0.82% 95.34%     3.01MB  0.82%  github.com/cockroachdb/cockroach/storage.(*CommandQueue).getWait

I'm a little confused, is this status normal?

a6802739 avatar May 27 '16 09:05 a6802739

Quite a big discrepancy between what pprof is reporting (368 MB) and the Go in Use stat (2.2 Gib). I wonder what is causing that. Oh, perhaps the heap profiling numbers shown in pprof aren't scaled by the sampling rate. Regardless, I'm surprised to see so much memory tied up in SQL parser structures. Besides the addition of the index, is there other load being sent to the system?

The resident set size (RSS) is huge. @a6802739 what sort of system are you running on? Did you configure the --cache-size setting on the command line or are you relying on the auto-selected value?

petermattis avatar May 27 '16 14:05 petermattis

@petermattis, except the addition of the index, there is no other load. I didn't configure --cache-size, it's default value. my server's real memory is 48G.

a6802739 avatar May 30 '16 02:05 a6802739

I don't think the difference is the pprof sampling rate - the ratio between 368MB and 2.2GiB is 6:1, which wouldn't make sense for heap sampling. Note that "Go in use" in our UI maps to MemStats.Alloc, not MemStats.HeapInUse. The docs aren't very clear about what's included in each these stats. One difference is goroutine stacks, but I can see part of the goroutine graph in your screenshots and it looks stable. Maybe it's the (non-garbage-collectable) data allocated by go to pass into c++?

If all load besides the schema change has stopped, you shouldn't be seeing so many parsed numbers in memory (schema changes don't go through the text parser). Are we leaking/caching those somewhere we shouldn't? If your client is using prepared statements, are you cleaning them up?

bdarnell avatar May 30 '16 17:05 bdarnell

@bdarnell I can't quite understand If your client is using prepared statements, are you cleaning them up?, I execute this command in cockroachdb's shell.

a6802739 avatar Jun 01 '16 07:06 a6802739

My question was about the INSERT commands, not the CREATE INDEX. Are you piping those insert statements as strings into cockroach sql?

bdarnell avatar Jun 01 '16 12:06 bdarnell

@bdarnell , the client will wait the insert statement finish and then execute next command. my client which executes the batch insert has already stopped, so i doubt this problem has matter with the insert statement.

a6802739 avatar Jun 02 '16 09:06 a6802739

Most of the memory usage comes from (*sqlParserImpl).Parse, which would be used mainly for the insert statements. If that data is staying in memory after the insert statements have stopped, then that should be a clue about where the bug is. We have something that is holding on to the results of query parsing longer than necessary.

bdarnell avatar Jun 02 '16 18:06 bdarnell

Unassigning myself since I'm not actively looking at this.

bdarnell avatar Jul 10 '16 20:07 bdarnell