# Activity return to workflow took 30 milliseconds

**URL:** <https://community.temporal.io/t/activity-return-to-workflow-took-30-milliseconds/6399>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [November 2, 2022, 6:08pm UTC](https://community.temporal.io/t/activity-return-to-workflow-took-30-milliseconds/6399 "2022-11-02T18:08:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aswath\_Murugan](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/aswath_murugan/32/162_2.png) [@Aswath\_Murugan](https://community.temporal.io/u/Aswath_Murugan)\
**Post date:** [November 2, 2022, 6:08pm UTC](https://community.temporal.io/t/activity-return-to-workflow-took-30-milliseconds/6399/1 "2022-11-02T18:08:04Z")

</div>

Hi All,

Am working on workflow optimization of my workflow execution, in that i have found that Activity took around 30 milliseconds to return the result back to workflow.Is this expected?  
Example code  
Workflow

```auto
logger.info("[CALL] Activity Started {}", System.currentTimeMillis());
      CallActivity callActivity =
          Workflow.newActivityStub(CallActivity.class, activityOptions);

      //Make external call
      String response = callActivity.call(stepName, translatedCall, topParentFlowId);
     logger.info("[Workflow] Total time took rest activity {}", total);

```

Activity:

```auto
 @Override
    public String call(String stepName, Call call, String workflowId)
        throws CheckedExternalException {
        long start = System.currentTimeMillis();
        logger.info("[CALL Activity] Activity started {}", workflowId);
        String result = callAsync(call, workflowId);
        long end = System.currentTimeMillis();
        long total = end - start;
        logger.info("[CALL Activity] Activity completed {}", total);
        return result;
    }

```

My Sample log:

```auto
[CALL Activity] Activity started 
[CALL Activity] Activity completed 169
[Workflow] Total time took rest activity 201

```

As per my log time taken to retrun back to workflow 32 milliseconds, Is this expected?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 2, 2022, 10:05pm UTC](https://community.temporal.io/t/activity-return-to-workflow-took-30-milliseconds/6399/3 "2022-11-02T22:05:56Z")

</div>

Hi, Temporal provides both SDK and server metrics as well as support for tracing which would give you a much better insight of your performances rather than using system outs.

Check out the sdk [metrics](https://github.com/temporalio/samples-java/tree/main/src/main/java/io/temporal/samples/metrics) and [tracing](https://github.com/temporalio/samples-java/tree/main/src/main/java/io/temporal/samples/tracing) samples, and worker tuning guide in docs [here](https://docs.temporal.io/application-development/worker-performance).

For sdk metrics look at

```auto
workflow_task_schedule_to_start_latency
activity_schedule_to_start_latency
workflow_endtoend_latency
activity_succeed_endtoend_latency

```

From server metrics you can measure

```auto
service_latency
persistence_latency
service_latency_userlatency
service_latency_nouserlatency

```

Note the overall workflow exec (end to end latencies) will depend on things like network latencies betwen your workers and service, persistence latencies, different types of service latencies etc. These things need to be taken into account if asking if certain execution time is expected or not.

Would start with tracing and sdk metrics to get an overall picture of workflow and each individual activity invocations and workflow / activity task latencies and then move to server metrics, first check persistence latencies and go from there.

---

<div class="post-metadata">

**Author:** ![Aswath\_Murugan](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/aswath_murugan/32/162_2.png) [@Aswath\_Murugan](https://community.temporal.io/u/Aswath_Murugan)\
**Post date:** [November 4, 2022, 5:24pm UTC](https://community.temporal.io/t/activity-return-to-workflow-took-30-milliseconds/6399/4 "2022-11-04T17:24:50Z")

</div>

Thanks for the reply, I have checked the Persistence latency

Problem:  
I have Workflow with one Activity that makes an external rest call. I have calculated the external timing etc. once the response is back to the activity. the handover from activity to the workflow I see 120 milliseconds diff.

Setup details:  
Running the Temporal server and my application K8 under the same cluster and using Postgres AWS RDS

Please find below the image of Persistence latency for the Last 7 days

 ![image](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/0/0c47ac8e627910664cfc74af596eae0cc6dde810.jpeg)

Persistence latency UpdateTaskqueue

 ![image](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/5/52f9b97f7433ca2c875bb12a6215433875e2ed67.png)

Can you please suggest, which operation should be monitored? is there documentation on the operation shown in the chart?  
Eg: what is CompleteTasksLessThan?
