Bug #9251
cache the translated FQL in FQLPreprocessor.translate
100%
History
#1 Updated by Constantin Asofiei almost 2 years ago
We need a LRU cache for the FQLPreprocessor.translate result. The cache key will be similar to existing FQL keys, but without parameters and maybe others (keep it simple, just the bound/definition aliases, original where, etc).
Alexandru: can you add this to the existing sprint?
#2 Updated by Alexandru Lungu almost 2 years ago
Alexandru: can you add this to the existing sprint?
Ok; do you have a small test-case in which that part of code is hit - to be used for testing?
#3 Updated by Constantin Asofiei almost 2 years ago
The recreate is this:
def temp-table tt1 reference-only field f1 as int.
def temp-table tt2 field f2 as int.
def var k as int.
procedure proc0.
def input parameter table for tt1 bind.
for each tt1 where tt1.f1 > 0:
k = k + 1.
end.
end.
create tt2.
tt2.f2 = 10.
release tt2.
def var i as int.
def var l1 as int64.
def var l2 as int64.
l1 = mtime.
do i = 1 to 100000:
run proc0(input table tt2 bind) .
end.
l2 = mtime.
message k "in" (l2 - l1) "ms".
Try to also cache the translateSort result.
Main focus here is memory reduction.
#4 Updated by Alexandru Lungu almost 2 years ago
- Assignee set to Stefanel Pezamosca
#6 Updated by Stefanel Pezamosca almost 2 years ago
- % Done changed from 0 to 50
- Status changed from New to WIP
I have created branch 9251a from trunk revision 15498.
I committed to revision 15499 the implementation for caching the translate() output.
- with trunk fastest time was ~800 ms
- with 9251a fastest time was ~500 ms
Next, I will try with translateSort output.
Edit: I committed to 9251a revision 15500: bound.size() and definition.size() will have the same value. Iterate using bound.size().
#7 Updated by Stefanel Pezamosca almost 2 years ago
- % Done changed from 50 to 80
- Status changed from WIP to Review
First try: it seems like caching the translateSort output does not bring any improvements.
Please review the translate() cache implementation in 9251a.
#8 Updated by Constantin Asofiei almost 2 years ago
Stefanel Pezamosca wrote:
First try: it seems like caching the
translateSortoutput does not bring any improvements.
Please add an index to both temp-tables and test with that.
#9 Updated by Stefanel Pezamosca almost 2 years ago
- % Done changed from 80 to 100
I committed to revision 15501: Added caching for translateSort(RecordBuffer, RecordBuffer, String) output.
Please review.
#10 Updated by Constantin Asofiei almost 2 years ago
- Status changed from Review to Merge Pending
The changes look good. I've ran ETF and #9214 and they are OK.
You can merge to trunk now.
#11 Updated by Stefanel Pezamosca almost 2 years ago
- Status changed from Merge Pending to Test
Branch 9251a was merged into trunk as rev. 15503 and archived.
#12 Updated by Ovidiu Maxiniuc almost 2 years ago
Stefanel Pezamosca wrote:
Without being in my intention to do so, I looked over trunk/r15503. I would like to highlight two issues:I committed to revision 15501: Added caching for translateSort(RecordBuffer, RecordBuffer, String) output.
Please review.
- the synchronization. In
AbstractQuery.translateSort()and also inFQLPreprocessor.translate(), when thesortCache/translateCacheare accessed, thegetandputuse differentsynchronizedblocks. The problem is that between them, other thread may access the cache object. I think a single lock on it should span on both accesses; - possible NPE in
FQLPreprocessor$TranslateCacheKey. When the objects are compared inequals(),where.equals(that.where)is used. When the translate is called fromAbstractQuery.translateWhere(), there is a guard fornullwhere, but if the call comes from one of thestaticBuffer.delete()methods, thewhereparameter may benull.
#13 Updated by Constantin Asofiei almost 2 years ago
Ovidiu Maxiniuc wrote:
- the synchronization. In
AbstractQuery.translateSort()and also inFQLPreprocessor.translate(), when thesortCache/translateCacheare accessed, thegetandputuse differentsynchronizedblocks. The problem is that between them, other thread may access the cache object. I think a single lock on it should span on both accesses;
I would rather avoid lock contention and let the threads do some additional work, but with the same results.
- possible NPE in
FQLPreprocessor$TranslateCacheKey. When the objects are compared inequals(),where.equals(that.where)is used. When the translate is called fromAbstractQuery.translateWhere(), there is a guard fornullwhere, but if the call comes from one of thestaticBuffer.delete()methods, thewhereparameter may benull.
Good catch. Stefanel: please add check at the top of FQLPreprocessor.translate, if the where clause is null, just exit and return null, as there is nothing to translate or cache.
#14 Updated by Stefanel Pezamosca almost 2 years ago
- File 9251b.patch
added
Good catch. Stefanel: please add check at the top of FQLPreprocessor.translate, if the where clause is null, just exit and return null, as there is nothing to translate or cache.
I have created branch 9251b from trunk 15504 and committed to revision 15505.
#15 Updated by Greg Shah over 1 year ago
What are the next steps with 9251b?
#16 Updated by Stefanel Pezamosca over 1 year ago
9251b should have been merged to trunk. It's just a null check.
#17 Updated by Greg Shah over 1 year ago
- Status changed from Test to Merge Pending
You can merge to trunk now.
#18 Updated by Stefanel Pezamosca over 1 year ago
- Status changed from Merge Pending to Test
Branch 9251b was merged into trunk as rev. 15572 and archived.
#20 Updated by Stefanel Pezamosca over 1 year ago
- File 9251c.patch
added - Status changed from Test to WIP
- reviewer Constantin Asofiei added
As pointed out by Eduard [es], there seems to be a regression related with the addition of this cache:
We cache the the where phrases in a map by TranslateCacheKey which consists of dmoAlias of the bound buffer, dmoAlias of the definition buffer, and where phrase.
The bound buffer can be a static temp-table or a dynamic temp-table created like a static temp-table. For example bound buffer could be a buffer for a static-table tt2Buf2 or a
buffer for dynamic table created like tt2Buf2. The problem is that for both cases getDMOAlias() will return the same thing tt2Buf2.But fields names in sql tables are different: for static-table fields are (domaincode, ...) and for dynamic-table (field1, field2, ...).
Constantin mentioned:
About the translation cache issues: using just the DMO alias looks to be wrong - we need to have a pair of (DMO class name, DMO alias) instead of just the alias.
So I made a patch that should improve this.
I will create a branch for this shortly.
#21 Updated by Stefanel Pezamosca over 1 year ago
- Status changed from WIP to Review
I have created task branch 9251c from trunk revision 15630.
The patch is committed in revision 15631. Please review.
#22 Updated by Constantin Asofiei over 1 year ago
Please add javadoc for the new params for the ctors in SortCacheKey and TranslateCacheKey. OTherwise 9251c/15631 looks ok. Please work with Eduard to confirm that the 7156d bug is solved with this.
#23 Updated by Stefanel Pezamosca over 1 year ago
Constantin Asofiei wrote:
Please add javadoc for the new params for the ctors in
SortCacheKeyandTranslateCacheKey. OTherwise 9251c/15631 looks ok. Please work with Eduard to confirm that the 7156d bug is solved with this.
javadoc fixed in revision 15632.
#24 Updated by Eduard Soltan over 1 year ago
I tested the patch from #9251-20, and tested a few modules in the unit tests in a large customer application and did not encounter the regressions that I mentioned in #9494-1 and #9494-4.
#25 Updated by Stefanel Pezamosca over 1 year ago
- Status changed from Review to Internal Test
Considering that 9251c is fixing the regression mentioned and I also retested #9251-3 with similar results, I guess that is ready to be merged?
#26 Updated by Constantin Asofiei over 1 year ago
Stefanel Pezamosca wrote:
Considering that 9251c is fixing the regression mentioned and I also retested #9251-3 with similar results, I guess that is ready to be merged?
What other testing did you do/is needed?
Please update the copyright year in the changed files.
#27 Updated by Stefanel Pezamosca over 1 year ago
Constantin Asofiei wrote:
Stefanel Pezamosca wrote:
Considering that 9251c is fixing the regression mentioned and I also retested #9251-3 with similar results, I guess that is ready to be merged?
What other testing did you do/is needed?
I ran the same tests that were done before for the 9251a and they are ok.
Please update the copyright year in the changed files.
Done.
#28 Updated by Constantin Asofiei over 1 year ago
- Status changed from Internal Test to Merge Pending
This can be merged to trunk now.
#29 Updated by Stefanel Pezamosca over 1 year ago
- Status changed from Merge Pending to Test
Branch 9251c was merged to trunk as rev. 15636 and archived.