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

[eleveldb][leo_backend_db] Impl iterater_move in batch #994

Closed
mocchira opened this issue Feb 10, 2018 · 5 comments
Closed

[eleveldb][leo_backend_db] Impl iterater_move in batch #994

mocchira opened this issue Feb 10, 2018 · 5 comments

Comments

@mocchira
Copy link
Member

mocchira commented Feb 10, 2018

As it turned out that interactions (to be precise, sending a message from an OS thread to an erlang scheduler thread) between erlang runtime and NIF are NOT negligible (hogged CPU rather than Disk I/O) especially if the number of call times is relatively large (For more details and evidences, see #974).
leo-project/eleveldb@61c1f5b has solved #974 by making the number of interactions from the number of records to 1 so let's take a step forward with this method, we can make this hack being applied to other iterator functions by adding a new I/F to eleveldb to iterate over items in a certain batch size, for example,

    %% This may return 30 items in BatchItems at most or less than 30 if it hits EOF.
    %% We can expect this function to decrease the CPU cost as it lowers the number of interactions between erlang runtime and NIF.
    {ok, BatchItems} = eleveldb:iterator_next_in_batch(IterRef, 30, []),

With this hack, we might be able to solve #710.
I'm going to try on the next working day.

@yosukehara
Copy link
Member

@mocchira I've just confirmed your idea. I agree to it.

@mocchira
Copy link
Member Author

@yosukehara Thanks for taking time. I will go ahead from now.

@mocchira mocchira added this to the 1.4.0 milestone Feb 16, 2018
@mocchira mocchira self-assigned this Feb 16, 2018
@mocchira
Copy link
Member Author

After some experiments, I've decided to change the new I/F as below.

    %% This may return 30 items in BatchItems at most or less than 30 if it hits EOF.
    %% We can expect this function to decrease the CPU cost as it lowers the number of interactions between erlang runtime and NIF.
    {ok, BatchItems} = eleveldb:first_n(DBRef, 30),

Comparison to the previous I/F

  • Pros
    • Much less code
    • Completely independent to the existing iterator related code base
  • Cons
    • Use cases are narrowed down

However the iterating function we are using in leo_mq now is ONLY

  • leo_backend_db_server:first_n

That said, just covering the first_n use case would solve most of our CPU hog problem for now.

@yosukehara
Copy link
Member

@mocchira I've reviewed your idea, and I agree to deliver its function:

the first_n use case would solve most of our CPU hog problem

{ok, BatchItems} = eleveldb:first_n(DBRef, NumberOfItems)

@mocchira
Copy link
Member Author

mocchira commented Mar 7, 2018

Confrimed this works fine. however unfortunately this improvement couldn't solve the #710 so I'll close this issue while leaving #710 open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants