Java的Ray.get()需要耗时1s多是正常的吗

【Ray版本和类库】2.5.1
【代码】

package ray;

import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;

import java.io.Serializable;

public class SpeedTest {
   public static class Actor implements Serializable {
       public static long test(long sendTime) {
           long time = System.currentTimeMillis() - sendTime;
           System.out.println("take time:" + time);
           return time;
       }

       public long actorTest(long sendTime) {
           long time = System.currentTimeMillis() - sendTime;
           System.out.println("take time:" + time);
           return time;
       }
   }
   static void testActorSpeed() throws Exception {
       ObjectRef<Long> ref = Ray.task(Actor::test, System.currentTimeMillis()).setResource("CPU", 1.0).remote();
       long getSumPvStartMills1 = System.currentTimeMillis();
       long time = ref.get();
       System.out.println("common task receive took time: ms " + time + " get takes time " + (System.currentTimeMillis() - getSumPvStartMills1));
       ActorHandle<Actor> handle = Ray.actor(Actor::new).remote();
       ObjectRef<Long> actorRef = handle.task(Actor::actorTest, System.currentTimeMillis()).remote();

       long t1 = System.currentTimeMillis();
       long actorTime = actorRef.get();
       System.out.println("actor task receive took time: ms " + actorTime + " get takes time " + (System.currentTimeMillis() - t1));
   }

   public static void main(String[] args) throws Exception {
       // Intialize Ray runtime.
       Ray.init();
       testActorSpeed();
   }
}

相关截图/链接/日志/监控等信息
Tailing logs until the job exits (disable with --no-wait):
Listening for transport dt_socket at address: 52000
common task receive took time: ms 1676 get takes time 1653
actor task receive took time: ms 1653 get takes time 1659

Ray.get()需要耗时1s多是正常的吗

大佬们求回复啊,问题可能出在哪里,能从哪几方面改善呢?

好像主要是java进程启动耗时久,当我使用detached actor时候就只需要几十毫秒了,但是task的话好像避免不了

看起来是的,java进程启动会比较慢。但task的worker可以复用,比如你连续发很多个,可以试试效果?还有个参数 idle_worker_killing_time_threshold_ms 可以调节杀idle worker的数量,默认1000ms,你如果调大,也会尽量走worker复用。