Skip to content

Experimental: enable automatic GCS flushing with configurable policy. - #2266

Merged
pcmoritz merged 9 commits into
ray-project:masterfrom
concretevitamin:flush-integrate
Jun 20, 2018
Merged

pcmoritz merged 9 commits into
ray-project:masterfrom
concretevitamin:flush-integrate

Conversation

@concretevitamin

Copy link
Copy Markdown
Contributor

Example usage illustrated in this test program (which submits no-op tasks continuously).

import subprocess
import time

import ray
# Pass this flag to avoid annoying output on program exit.
info = ray.init(redirect_worker_output=True)

# Turn on flushing with the next two lines.
pol = ray.experimental.SimpleGcsFlushPolicy(
    flush_when_at_least_bytes=0,
    flush_period_secs=1e-4,
    flush_num_entries_each_time=10000)
ray.experimental.set_flushing_policy(pol)


@ray.remote
def noop():
    return


time.sleep(1)
primary_port = info['redis_address'].split(':')[-1]
pid = subprocess.run(
    ['pgrep', '-f', 'redis-server.*{}'.format(primary_port)],
    stdout=subprocess.PIPE).stdout[:-1].decode()
logfile = 'psrecord-{}.log'.format(primary_port)
args = [
    'psrecord', pid, '--interval', '1', '--duration', '40', '--log', logfile
]
print(' '.join(args))
subprocess.Popen(args)

num_noops = 200000
i = 0
start = time.time()
while i < num_noops:
    noop.remote()
    i += 1
print('Time to execute {} no-ops: {:.2f} seconds'.format(
    num_noops,
    time.time() - start))

Result shows that the policy can control memory usage to the minimum possible level, on the primary redis server.
memory_plot

@AmplabJenkins

Copy link
Copy Markdown

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6087/
Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6093/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6101/
Test FAILed.

int ChainTableAdd_RedisCommand(RedisModuleCtx *ctx,
RedisModuleString **argv,
int argc) {
RedisModule_AutoMemory(ctx);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did this fix the problem you were seeing with memory not being reclaimed even when flushing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's right.

@pcmoritz

Copy link
Copy Markdown
Contributor

Jenkins retest this please

@pcmoritz pcmoritz left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is a Python linting error on travis and also the following error in the RAY_USE_NEW_GCS build:

======================================================================
ERROR: test_credis_started (__main__.CredisTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/credis_test.py", line 31, in test_credis_started
    chain = primary.execute_command('MASTER.GET_CHAIN')
  File "/home/travis/.local/lib/python3.6/site-packages/redis-2.10.6-py3.6.egg/redis/client.py", line 668, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "/home/travis/.local/lib/python3.6/site-packages/redis-2.10.6-py3.6.egg/redis/client.py", line 680, in parse_response
    response = connection.read_response()
  File "/home/travis/.local/lib/python3.6/site-packages/redis-2.10.6-py3.6.egg/redis/connection.py", line 629, in read_response
    raise response
redis.exceptions.ResponseError: unknown command 'MASTER.GET_CHAIN'

----------------------------------------------------------------------

ray.worker.global_worker.check_connected()
redis_client = ray.worker.global_worker.redis_client

serialized = flushing_policy.serialize()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Given that the corresponding deserialization call is self.gcs_flush_policy = pickle.loads(serialized), shouldn't we just call pickle.dumps here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call. Adding serialize() to the abstract interface is probably overkill.

Comment thread python/ray/monitor.py
self.redis.execute_command("HEAD.FLUSH 0")
except redis.exceptions.ResponseError as e:
log.info("Turning off flushing due to exception: {}".format(
str(e)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This would be a good place to push an error to the driver I think (ray.utils.push_error_to_driver).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems complicated for a harmless operating mode

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If an exception raised here, isn't that a bug?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can happen when (1) Ray is not compiled from source with the flag RAY_USE_NEW_GCS, (2) BUT somehow at run time RAY_USE_NEW_GCS is provided. This seems a harmless setup issue, not a bug?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's important to push an error to the driver here. Otherwise the user will spend a lot of time trying to figure out what is going wrong.

if time.time() - self.last_flush_timestamp < self.flush_period_secs:
return False

reply = redis_client.execute_command("INFO MEMORY")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

redis_client.info("memory")["used_memory"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great catch! Thanks.

# Set up logging.
logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem like the right place to set up a global logging variable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed these.

return pickle.dumps(self)


def set_flushing_policy(flushing_policy):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Raise an exception when this is called if we are not using the new GCS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6133/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6145/
Test FAILed.

@concretevitamin concretevitamin left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, PTAL?

# Set up logging.
logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed these.

if time.time() - self.last_flush_timestamp < self.flush_period_secs:
return False

reply = redis_client.execute_command("INFO MEMORY")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great catch! Thanks.

return pickle.dumps(self)


def set_flushing_policy(flushing_policy):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

ray.worker.global_worker.check_connected()
redis_client = ray.worker.global_worker.redis_client

serialized = flushing_policy.serialize()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call. Adding serialize() to the abstract interface is probably overkill.

Comment thread python/ray/monitor.py
self.redis.execute_command("HEAD.FLUSH 0")
except redis.exceptions.ResponseError as e:
log.info("Turning off flushing due to exception: {}".format(
str(e)))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems complicated for a harmless operating mode

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6148/
Test PASSed.

Comment thread python/ray/monitor.py

max_entries_to_flush = self.gcs_flush_policy.num_entries_to_flush()
num_flushed = self.redis.execute_command(
"HEAD.FLUSH {}".format(max_entries_to_flush))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not expose a thin wrapper around this command? That would give users the maximum flexibility.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it's important/beneficial to emphasize the automatic aspect of this feature. This will encourage the users to play with the simple policy first. We want to develop that to a mature enough degree.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sure, but then for it to be useful it needs to work perfectly. If we expose this command then the bar is lower and the user will usually be able to work around problems.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6154/
Test PASSed.

@concretevitamin

Copy link
Copy Markdown
Contributor Author

Travis is green now modulo valgrind

@pcmoritz
pcmoritz merged commit 8190ff1 into ray-project:master Jun 20, 2018
royf added a commit to royf/ray that referenced this pull request Jun 22, 2018
* 'master' of https://github.com/ray-project/ray: (157 commits)
  Fix build failure while using make -j1. Issue 2257 (ray-project#2279)
  Cast locator with index type (ray-project#2274)
  fixing zero length partitions (ray-project#2237)
  Make actor handles work in Python mode. (ray-project#2283)
  [xray] Add error table and push error messages to driver through node manager. (ray-project#2256)
  addressing comments (ray-project#2210)
  Re-enable some actor tests. (ray-project#2276)
  Experimental: enable automatic GCS flushing with configurable policy. (ray-project#2266)
  [xray] Sets good object manager defaults. (ray-project#2255)
  [tune] Update Trainable doc to expose interface (ray-project#2272)
  [rllib] Add a simple REST policy server and client example (ray-project#2232)
  [asv] Pushing to s3 (ray-project#2246)
  [rllib] Remove need to pass around registry (ray-project#2250)
  Support multiple availability zones in AWS (fix ray-project#2177) (ray-project#2254)
  [rllib] Add squash_to_range model option (ray-project#2239)
  Mitigate randomly building failure: adding gen_local_scheduler_fbs to raylet lib. (ray-project#2271)
  [rllib] Refactor Multi-GPU for PPO (ray-project#1646)
  [rllib] Envs for vectorized execution, async execution, and policy serving (ray-project#2170)
  [Dataframe] Change pandas and ray.dataframe imports (ray-project#1942)
  [Java] Replace binary rewrite with Remote Lambda Cache (SerdeLambda) (ray-project#2245)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants