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

Don't read posting lists from disk when mutating indices. #3695

Merged
merged 6 commits into from
Jul 23, 2019

Conversation

martinmr
Copy link
Contributor

@martinmr martinmr commented Jul 19, 2019

Adding index mutations can be performed without reading the posting
lists in disk. This change modifies the indexing process to avoid
reading any list from disk. It should result in performance
improvements, specially when trying to modify big index posting lists.


This change is Reviewable

Adding index mutations can be performed without reading the posting
lists in disk. This change modifies the indexing process to avoid
reading any list from disk. It should result in performance
improvements, specially when trying to modify big index posting lists.
Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @martinmr)


posting/lists.go, line 247 at r1 (raw file):

// GetFromDelta gets the cached version of the list without reading from disk
// and only applies the existing deltas. This is used in situations where the
// posting list will only be modified and not read (e.g adding index mutations).

Add a comment that this is largely a copy of the logic from Get. So, keep this in-sync with above.

Actually, let's refactor this. Internally, call a get func:


posting/lists.go, line 260 at r1 (raw file):

	// immutable layer.
	pl := &List{}
	pl.key = key

Put it in the constructor:

&List{
  key: key,
  mutationMap: ...
}

posting/oracle.go, line 83 at r1 (raw file):

// If there's a cache miss, the posting list stored on disk will not be read.
// See documentation for LocalCache.GetFromDelta for more info.
func (txn *Txn) GetFromDelta(key []byte) (*List, error) {

No need to expose this func.

Copy link
Contributor Author

@martinmr martinmr left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @manishrjain)


posting/lists.go, line 247 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Add a comment that this is largely a copy of the logic from Get. So, keep this in-sync with above.

Actually, let's refactor this. Internally, call a get func:

Done, refactored both methods into an internal method.


posting/lists.go, line 260 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Put it in the constructor:

&List{
  key: key,
  mutationMap: ...
}

Done.


posting/oracle.go, line 83 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

No need to expose this func.

Done.

@martinmr
Copy link
Contributor Author

Copy link

@gitlw gitlw left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @manishrjain and @martinmr)


posting/index.go, line 940 at r2 (raw file):

		// Ensure that list is in the cache run by txn. Otherwise, nothing would
		// get updated.
		pl = txn.cache.Set(string(pl.key), pl)

I don't understand the logic behind setting the result back to pl.

Also it seems the code can be improved so that in builder.Run the posting list is NOT pre-loaded, but lazily loaded whenever it's needed later through txn.Get(key), which takes care of putting the posting list into the txn.cache as well.

Copy link
Contributor Author

@martinmr martinmr left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @gitlw and @manishrjain)


posting/index.go, line 940 at r2 (raw file):

Previously, gitlw (Lucas Wang) wrote…

I don't understand the logic behind setting the result back to pl.

Also it seems the code can be improved so that in builder.Run the posting list is NOT pre-loaded, but lazily loaded whenever it's needed later through txn.Get(key), which takes care of putting the posting list into the txn.cache as well.

There shouldn't be any functional change. This is just to highlight that Set returns a value.

I have done the change you suggested. I need to check with Manish that the cache will work fine in the case of a rebuild.

@martinmr martinmr requested a review from gitlw July 22, 2019 18:49
@martinmr
Copy link
Contributor Author

Ran some benchmarks by letting the live loader run for 2.5 minutes.

With the current changes:

➜  data git:(master) dgraph live -a localhost:9180 --zero localhost:5180 --files 21million.rdf.gz -s 21million.schema
[Decoder]: Using assembly version of decoder
I0722 11:41:57.988611   17772 init.go:93]

Dgraph version   : v1.0.12-rc3-613-g17157d0d
Commit SHA-1     : 17157d0d
Commit timestamp : 2019-07-22 10:46:13 -0700
Branch           : martinmr/indexing-no-plist-read
Go version       : go1.12.7

For Dgraph official documentation, visit https://docs.dgraph.io.
For discussions about Dgraph     , visit https://discuss.dgraph.io.
To say hi to the community       , visit https://dgraph.slack.com.

Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2018 Dgraph Labs, Inc.



Running transaction with dgraph endpoint: localhost:9180

Processing schema file "21million.schema"
Processed schema file "21million.schema"

Found 1 data file(s) to process
Processing data file "21million.rdf.gz"
[11:42:03-0700] Elapsed: 05s Txns: 327 N-Quads: 327000 N-Quads/s [last 5s]: 65400 Aborts: 47
[11:42:08-0700] Elapsed: 10s Txns: 701 N-Quads: 701000 N-Quads/s [last 5s]: 74800 Aborts: 110
[11:42:13-0700] Elapsed: 15s Txns: 1023 N-Quads: 1023000 N-Quads/s [last 5s]: 64400 Aborts: 175
[11:42:18-0700] Elapsed: 20s Txns: 1367 N-Quads: 1367000 N-Quads/s [last 5s]: 68800 Aborts: 240
[11:42:23-0700] Elapsed: 25s Txns: 1697 N-Quads: 1697000 N-Quads/s [last 5s]: 66000 Aborts: 294
[11:42:28-0700] Elapsed: 30s Txns: 2013 N-Quads: 2013000 N-Quads/s [last 5s]: 63200 Aborts: 350
[11:42:33-0700] Elapsed: 35s Txns: 2314 N-Quads: 2314000 N-Quads/s [last 5s]: 60200 Aborts: 401
[11:42:38-0700] Elapsed: 40s Txns: 2643 N-Quads: 2643000 N-Quads/s [last 5s]: 65800 Aborts: 457
[11:42:43-0700] Elapsed: 45s Txns: 2942 N-Quads: 2942000 N-Quads/s [last 5s]: 59800 Aborts: 499
[11:42:48-0700] Elapsed: 50s Txns: 3176 N-Quads: 3176000 N-Quads/s [last 5s]: 46800 Aborts: 545
[11:42:53-0700] Elapsed: 55s Txns: 3347 N-Quads: 3347000 N-Quads/s [last 5s]: 34200 Aborts: 582
[11:42:58-0700] Elapsed: 01m00s Txns: 3542 N-Quads: 3542000 N-Quads/s [last 5s]: 39000 Aborts: 615
[11:43:03-0700] Elapsed: 01m05s Txns: 3732 N-Quads: 3732000 N-Quads/s [last 5s]: 38000 Aborts: 644
[11:43:08-0700] Elapsed: 01m10s Txns: 3881 N-Quads: 3881000 N-Quads/s [last 5s]: 29800 Aborts: 668
[11:43:13-0700] Elapsed: 01m15s Txns: 4053 N-Quads: 4053000 N-Quads/s [last 5s]: 34400 Aborts: 695
[11:43:18-0700] Elapsed: 01m20s Txns: 4224 N-Quads: 4224000 N-Quads/s [last 5s]: 34200 Aborts: 726
[11:43:23-0700] Elapsed: 01m25s Txns: 4388 N-Quads: 4388000 N-Quads/s [last 5s]: 32800 Aborts: 757
[11:43:28-0700] Elapsed: 01m30s Txns: 4560 N-Quads: 4560000 N-Quads/s [last 5s]: 34400 Aborts: 781
[11:43:33-0700] Elapsed: 01m35s Txns: 4716 N-Quads: 4716000 N-Quads/s [last 5s]: 31200 Aborts: 806
[11:43:38-0700] Elapsed: 01m40s Txns: 4909 N-Quads: 4909000 N-Quads/s [last 5s]: 38600 Aborts: 834
[11:43:43-0700] Elapsed: 01m45s Txns: 5094 N-Quads: 5094000 N-Quads/s [last 5s]: 37000 Aborts: 863
[11:43:48-0700] Elapsed: 01m50s Txns: 5270 N-Quads: 5270000 N-Quads/s [last 5s]: 35200 Aborts: 909
[11:43:53-0700] Elapsed: 01m55s Txns: 5459 N-Quads: 5459000 N-Quads/s [last 5s]: 37800 Aborts: 962
[11:43:58-0700] Elapsed: 02m00s Txns: 5644 N-Quads: 5644000 N-Quads/s [last 5s]: 37000 Aborts: 1014
[11:44:03-0700] Elapsed: 02m05s Txns: 5813 N-Quads: 5813000 N-Quads/s [last 5s]: 33800 Aborts: 1058
[11:44:08-0700] Elapsed: 02m10s Txns: 5990 N-Quads: 5990000 N-Quads/s [last 5s]: 35400 Aborts: 1108
[11:44:13-0700] Elapsed: 02m15s Txns: 6153 N-Quads: 6153000 N-Quads/s [last 5s]: 32600 Aborts: 1154
[11:44:18-0700] Elapsed: 02m20s Txns: 6320 N-Quads: 6320000 N-Quads/s [last 5s]: 33400 Aborts: 1213
[11:44:23-0700] Elapsed: 02m25s Txns: 6493 N-Quads: 6493000 N-Quads/s [last 5s]: 34600 Aborts: 1264
[11:44:28-0700] Elapsed: 02m30s Txns: 6667 N-Quads: 6667000 N-Quads/s [last 5s]: 34800 Aborts: 1307

With the current master:

➜  data git:(master) dgraph live -a localhost:9180 --zero localhost:5180 --files 21million.rdf.gz -s 21million.schema
[Decoder]: Using assembly version of decoder
I0722 11:46:33.076398   20235 init.go:93]

Dgraph version   : v1.0.12-rc3-614-ga1e36819
Commit SHA-1     : a1e36819
Commit timestamp : 2019-07-22 10:46:41 -0700
Branch           : master
Go version       : go1.12.7

For Dgraph official documentation, visit https://docs.dgraph.io.
For discussions about Dgraph     , visit https://discuss.dgraph.io.
To say hi to the community       , visit https://dgraph.slack.com.

Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2018 Dgraph Labs, Inc.



Running transaction with dgraph endpoint: localhost:9180

Processing schema file "21million.schema"
Processed schema file "21million.schema"

Found 1 data file(s) to process
Processing data file "21million.rdf.gz"
[11:46:39-0700] Elapsed: 05s Txns: 203 N-Quads: 203000 N-Quads/s [last 5s]: 40600 Aborts: 31
[11:46:44-0700] Elapsed: 10s Txns: 341 N-Quads: 341000 N-Quads/s [last 5s]: 27600 Aborts: 49
[11:46:49-0700] Elapsed: 15s Txns: 445 N-Quads: 445000 N-Quads/s [last 5s]: 20800 Aborts: 66
[11:46:54-0700] Elapsed: 20s Txns: 531 N-Quads: 531000 N-Quads/s [last 5s]: 17200 Aborts: 79
[11:46:59-0700] Elapsed: 25s Txns: 610 N-Quads: 610000 N-Quads/s [last 5s]: 15800 Aborts: 93
[11:47:04-0700] Elapsed: 30s Txns: 678 N-Quads: 678000 N-Quads/s [last 5s]: 13600 Aborts: 105
[11:47:09-0700] Elapsed: 35s Txns: 735 N-Quads: 735000 N-Quads/s [last 5s]: 11400 Aborts: 121
[11:47:14-0700] Elapsed: 40s Txns: 793 N-Quads: 793000 N-Quads/s [last 5s]: 11600 Aborts: 130
[11:47:19-0700] Elapsed: 45s Txns: 852 N-Quads: 852000 N-Quads/s [last 5s]: 11800 Aborts: 141
[11:47:24-0700] Elapsed: 50s Txns: 904 N-Quads: 904000 N-Quads/s [last 5s]: 10400 Aborts: 149
[11:47:29-0700] Elapsed: 55s Txns: 949 N-Quads: 949000 N-Quads/s [last 5s]:  9000 Aborts: 161
[11:47:34-0700] Elapsed: 01m00s Txns: 993 N-Quads: 993000 N-Quads/s [last 5s]:  8800 Aborts: 171
[11:47:39-0700] Elapsed: 01m05s Txns: 1037 N-Quads: 1037000 N-Quads/s [last 5s]:  8800 Aborts: 179
[11:47:44-0700] Elapsed: 01m10s Txns: 1082 N-Quads: 1082000 N-Quads/s [last 5s]:  9000 Aborts: 184
[11:47:49-0700] Elapsed: 01m15s Txns: 1127 N-Quads: 1127000 N-Quads/s [last 5s]:  9000 Aborts: 193
[11:47:54-0700] Elapsed: 01m20s Txns: 1164 N-Quads: 1164000 N-Quads/s [last 5s]:  7400 Aborts: 202
[11:47:59-0700] Elapsed: 01m25s Txns: 1204 N-Quads: 1204000 N-Quads/s [last 5s]:  8000 Aborts: 206
[11:48:04-0700] Elapsed: 01m30s Txns: 1238 N-Quads: 1238000 N-Quads/s [last 5s]:  6800 Aborts: 216
[11:48:09-0700] Elapsed: 01m35s Txns: 1269 N-Quads: 1269000 N-Quads/s [last 5s]:  6200 Aborts: 227
[11:48:14-0700] Elapsed: 01m40s Txns: 1304 N-Quads: 1304000 N-Quads/s [last 5s]:  7000 Aborts: 234
[11:48:19-0700] Elapsed: 01m45s Txns: 1339 N-Quads: 1339000 N-Quads/s [last 5s]:  7000 Aborts: 239
[11:48:24-0700] Elapsed: 01m50s Txns: 1375 N-Quads: 1375000 N-Quads/s [last 5s]:  7200 Aborts: 242
[11:48:29-0700] Elapsed: 01m55s Txns: 1406 N-Quads: 1406000 N-Quads/s [last 5s]:  6200 Aborts: 250
[11:48:34-0700] Elapsed: 02m00s Txns: 1440 N-Quads: 1440000 N-Quads/s [last 5s]:  6800 Aborts: 255
[11:48:39-0700] Elapsed: 02m05s Txns: 1471 N-Quads: 1471000 N-Quads/s [last 5s]:  6200 Aborts: 260
[11:48:44-0700] Elapsed: 02m10s Txns: 1502 N-Quads: 1502000 N-Quads/s [last 5s]:  6200 Aborts: 266
[11:48:49-0700] Elapsed: 02m15s Txns: 1532 N-Quads: 1532000 N-Quads/s [last 5s]:  6000 Aborts: 272
[11:48:54-0700] Elapsed: 02m20s Txns: 1563 N-Quads: 1563000 N-Quads/s [last 5s]:  6200 Aborts: 278
[11:48:59-0700] Elapsed: 02m25s Txns: 1595 N-Quads: 1595000 N-Quads/s [last 5s]:  6400 Aborts: 281
[11:49:04-0700] Elapsed: 02m30s Txns: 1625 N-Quads: 1625000 N-Quads/s [last 5s]:  6000 Aborts: 286

The new version is a bit more than 4X faster.

Copy link
Contributor Author

@martinmr martinmr left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @gitlw and @manishrjain)


posting/index.go, line 940 at r2 (raw file):

Previously, martinmr (Martin Martinez Rivera) wrote…

There shouldn't be any functional change. This is just to highlight that Set returns a value.

I have done the change you suggested. I need to check with Manish that the cache will work fine in the case of a rebuild.

Actually, I ended up reverting the changes because I need to check with Manish first whether the cache might grow without bounds and cause an OOM.

Also, I measured the performance without and with your suggestion and it's pretty much the same so I don't think it makes a huge difference.

Copy link

@gitlw gitlw left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @gitlw and @manishrjain)

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice optimization.

Reviewed 2 of 2 files at r4.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @gitlw)

@martinmr martinmr merged commit d697ca0 into master Jul 23, 2019
@martinmr martinmr deleted the martinmr/indexing-no-plist-read branch July 23, 2019 19:06
manishrjain added a commit that referenced this pull request Jul 24, 2019
To further #3695 , only read posting lists in certain cases. For e.g., when they are indexed, or when there's a delete operation or when it's a single UID predicate, etc. For the rest, don't read them. This further improves the performance of live data loading.

Changes:
* Avoid retrieving data keys if we don't need them to execute the mutation.
* Fix a test failure by retrieving in case of DEL operation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants