-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[Java] Replace binary rewrite with Remote Lambda Cache (SerdeLambda) #2245
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
[Java] Replace binary rewrite with Remote Lambda Cache (SerdeLambda) #2245
Conversation
Test PASSed. |
CACHE = ThreadLocal.withInitial(() -> new WeakHashMap<>()); | ||
|
||
/** | ||
* format A.B.C.cname |
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.
What is the meaning of this comment?
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.
ok, I would clean it.
|
||
public final class MethodId { | ||
|
||
/* use ThreadLocal to avoid lock. </br> |
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.
unmatched
?
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.
ok, I would clean it.
import org.ray.util.logger.RayLog; | ||
|
||
|
||
public final class MethodId { |
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.
Can we add a small comment on what this class is doing? I.e. it seems to be similar to our FunctionID in Ray, except it also has a class associated with it? Also, let's document the fields methodDesc and encoding, it's not clear to me at the moment what they are.
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.
ok, I would add the doc
if (m != null) { | ||
return m; | ||
} | ||
//it is a actor static func |
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.
there should be a space after the //
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.
ok, I would clean it.
} | ||
Pair<ClassLoader, RayMethod> getMethod(UniqueID driverId, UniqueID actorId, | ||
UniqueID methodId, String className) { | ||
//assert the driver's resource is load |
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.
space after //
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.
ok, I would clean it.
public static Pair<Object, Object[]> unwrap(TaskSpec task, Method m, ClassLoader classLoader) | ||
throws TaskExecutionException { | ||
FunctionArg[] fargs = task.args; | ||
//the last arg is className |
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.
space after //
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.
ok, I would clean it.
} | ||
|
||
public static void unloadJars(ClassLoader loader) { | ||
// TODO: |
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.
say what is to be done here (or if nothing, remove the todo)
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.
ok, I would add the doc
Thanks, this is really great! Some high level questions:
Also if functions are garbage collected from the WeakDictionary, they will be reloaded later, right? Where are the remote lambdas stored? |
with issue ray-project#2245
.gitignore
Outdated
*.iml | ||
java/test | ||
java/*/target | ||
java/target/ |
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.
Don't ignore java/test
, it's a valid module.
java/test
and java/*/target
can be combined as java/**/target
} | ||
|
||
|
||
public static SerializedLambda getSerializedLambda(Serializable lambda) { |
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.
Let's also use RayFunc
as the parameter type here.
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.
MethodId is not only for RayFunc, it clould used for all lambda call. the check of RayFunc has add in entrance
* Note: the lambda instances are dynamically created per call site, | ||
* we use WeakHashMap to avoid OOM. | ||
*/ | ||
private static final ThreadLocal<WeakHashMap<Class<Serializable>, MethodId>> |
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.
same here, RayFunc
.
and a lot of other places in the rest of this PR.
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.
MethodId is not only for RayFunc, it clould used for all lambda call. the check of RayFunc has add in entrance
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.
MethodId is not only for RayFunc, it clould used for all lambda call. the check of RayFunc has add in entrance
this.encoding = encode(className, methodName, methodDesc, isStatic); | ||
this.digest = getSha1Hash0(); | ||
} | ||
|
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.
nit: remove empty line
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.
ok
final SerializedLambda lambda = LambdaUtils.getSerializedLambda(serial); | ||
Preconditions.checkArgument(lambda.getCapturedArgCount() == 0, "could not transfer a lambda " | ||
+ "which is closure"); | ||
final boolean isstatic = lambda.getImplMethodKind() == MethodHandleInfo.REF_invokeStatic; |
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.
nit: isStatic
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.
ok
|
performancebinary rewrite is fastest. the functioId has computed in rewrite. No time overhead for functioId get. changes in semantics for the userthe serdeLambda didn't change the semantics for the user. the PR keep the Ray.call semantics. Do not conflict with this #2172 functions gcthe java func would not be gc, it only gc the MethodId. MethodId is a point to the called java function. what is the meaning of 'remote lambdas stored' ? I think, there is no need to store them. |
Test PASSed. |
Test FAILed. |
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.
LGTM, thanks for the changes!
* '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) ...
What do these changes do?
in java-worker, there are two ways to implement the ray.call: asm-rewrite and remote-lambda.
the asm-rewrite is not elegant and remote-lambda is too slow. And can not get the meta-information of the called function at runtime in the two solutions. e.g. @rayremote(xxx=yyy), at runtime we want to get the xxx=yyy.
the new solution: SerdeLambda( see org.ray.util.LambdaUtils). It has the following advantages: