google-deepmind / reverb

Reverb is an efficient and easy-to-use data storage and transport system designed for machine learning research
Apache License 2.0
700 stars 93 forks source link

Question about rate_limiters.SampleToInsertRatio #82

Closed xuehui1991 closed 2 years ago

xuehui1991 commented 2 years ago

Hello reverb team,

When using the client's writer to append data to the buffer, will the client be blocked if the condition of SampleToInsertRatio is not met? Or the client will run the next line code without blocking?

Thank you all.

Guess @acassirer could give me some answer?

acassirer commented 2 years ago

Hey,

Yes, the writer will block when the conditions of the rate limiter is not met. However, in order to allow users to control how much run-ahead is suitable this blocking only occur when calling flush and end_episode. It is therefore good practice to always call flush right after create_item to ensure the right level of run ahead.

For example:


with client.trajectory_writer(...) as writer:
  for step in episode:
    writer.append(step)
    ...
    writer.create_item(....)

    # Blocks until all but at most MAX_IN_FLIGHT_ITEMS items are inserted into the table.
    writer.flush(block_until_num_items=MAX_IN_FLIGHT_ITEMS)

  # Blocks until all pending items are inserted into the table.
  writer.end_episode()
xuehui1991 commented 2 years ago

@acassirer Thank you very much.