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
osd: reduce string use in coll_t::calc_str() #6505
Conversation
Looks reasonable to me. It might make sense to move part of this into [s]pg_t so that it sits next to operator<< (they need to match perfectly!) and have the coll_t one append _head or _TEMP as appropriate? |
a4f8de3
to
82cf1e4
Compare
@liewegas , I've moved calc_name into pg_t, but the buffer for the name sits in coll_t. I think it looks good except additional buf in operator<<(ostream& out, const pg_t &pg). |
Can you squash the commits and repush so the buildbot runs again? For the removal type, it is gone. I would remove it from everywhere. |
@liewegas , I've found bugs in my last commit and missing parts (spg_t). Probably tomorrow EOD I'll push fixed+squashed version. |
e7b8392
to
f64c60e
Compare
FAIL: test/encoding/readable.sh because ceph/ceph-object-corpus#2 should be merged first. |
@aiicore: Using those functions in separate C code (PoC) caused 11x reduction in cpu user time vs std::string and 2x vs sprintf() with the same pattern. |
@aclamk So it's even better that is deprecated ;) I'll remove it. About testing, I used /usr/bin/time -v (not time - because it's bash built in) on my separate binary that contained only std::strings, operators << +, sprintf and my new functions in a loop. After merging to ceph I used my ceph_monitor (see my repo - it's very very early project) to see if cpu user time is dropping on whole cluster, and it was a little bit. |
f64c60e
to
52d5557
Compare
@dachary, The test is failing, because it's done on version checked out on commit from my pool request (I think so), and there are no changes from test/encoding/readable.sh and ceph-object-corpus yet. Should I close and make new PR to trigger right version being build and tested? Or maybe there is some other way (from your side) to rebase my changes on top of current master and then do the test? |
@aiicore you need to git submodule update --remote ceph-object-corpus and repush with the updated reference to the ceph-object-corpus. |
52d5557
to
cbfff92
Compare
return 1; | ||
} | ||
|
||
while (i>=10) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: spaces around >=
Can you please separate this into two patches: one that gets rid of the removal pg type (and changes the submodule), and the second that optimizes the calc_name code? Thanks! |
@liewegas Yes I could separate it on two PR's but removal pg type would be the first one and string reduce - second, thereby I don't need to care about bigger char _str buffer for FORREMOVAL... type |
rebase? |
9d256aa
to
a0e5666
Compare
@aiicore I think, functions can be greatly simplified and speed up, if you pass pointer to the end of the buffer and start serializing from the end. |
@efirs I think you didn't even look what I've done in this PR :)
|
a0e5666
to
3951c32
Compare
@liewegas, forgot about style nit, pushed again. |
Signed-off-by: Evgeniy Firsov <evgeniy.firsov@sandisk.com>
And that's exactly what you could avoid, saving cpu.
Think, what if you start filling from the end in calc_name function, when you finish you'll have pointer to the beginning of what you just serialized. BTW, I did look at what you've done in the PR. Good job. Just wanted to help make it a little bit better. |
@efirs Thanks!, I thought that you looked only on dec/hex2char functions. Ok, when you refer to whole PR filing from the end in calc_str() could be faster. I wrote dec/hex2char in a way, that they can be used more global. I'll rewrite and check this locally, good tip! |
c0150f6
to
fb34e91
Compare
@efirs I think we'll have a compromise due function name ;) ritoa - like rindex (r = right). itoa - because arguments are just like in old/original itoa, so now it's one function to 10 and 16 base number. ritoa is also a template - to be consistent with your idea. |
@@ -523,7 +530,8 @@ class coll_t { | |||
spg_t pgid; | |||
uint64_t removal_seq; // note: deprecated, not encoded | |||
|
|||
string _str; // cached string | |||
char _str_buff[spg_t::calc_name_buf_size]; | |||
char *_str = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we need an operator=. Otherwise we'll copy the pointer value and bad things will happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I could save the _str_buff offset in a variable and use it in .to_str() and .c_str() and some other places like .parse(), so I could avoid operator=. I'll check on Monday those two options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to initialize _str, calc_str() will always take care of that.
But even if you need to you can always initialize it in the constructor initialization list.
With _str code will look cleaner than with _str_offset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@efirs Yep, calc_str() is called in constructors so no need for _str initialization. I'll revert to _str.
The rest looks reasonable to me! |
fb34e91
to
444d8d5
Compare
@aiicore LGTM, except _str_offset and base parameter I commented above. |
1. Reduce string use. 2. Speedup dec and hex to char conversion. Signed-off-by: Igor Podoski <igor.podoski@ts.fujitsu.com>
444d8d5
to
95e885e
Compare
osd: reduce string use in coll_t::calc_str() Reviewed-by: Sage Weil <sage@redhat.com> Reviewed-by: Evgeniy Firsov <evgeniy.firsov@sandisk.com>
This pull request should be treated as a concept of reducing string usage in well known fixed-scenarios. Functions dec2char and hex2char are faster than << hex << and sprintf() but less secure (they don't know anything about buffer size, and could easily cause buffer overflow).
Using those functions in separate C code (PoC) caused 11x reduction in cpu user time vs std::string and 2x vs sprintf() with the same pattern.
Running test on whole cluster caused cpu user time reduction, mostly for small write size and big number of threads/objects. Cpu time reduction is noticeable not significant, maybe touching similar places in code could cause bigger impact.
Code for deprecated options was added for compatibility.
Signed-off-by: Igor Podoski igor.podoski@ts.fujitsu.com