Commit e823dfb85d5d13cc47b8fb09ac33a69eff5f2d3b

Authored by Andrii Shvaika
1 parent 28f1993a

Min RPC timeout

... ... @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
20 20 import com.google.common.util.concurrent.FutureCallback;
21 21 import lombok.extern.slf4j.Slf4j;
22 22 import org.springframework.beans.factory.annotation.Autowired;
  23 +import org.springframework.beans.factory.annotation.Value;
23 24 import org.springframework.http.HttpStatus;
24 25 import org.springframework.http.ResponseEntity;
25 26 import org.springframework.security.access.prepost.PreAuthorize;
... ... @@ -65,7 +66,6 @@ import java.util.UUID;
65 66 @Slf4j
66 67 public class RpcController extends BaseController {
67 68
68   - public static final int DEFAULT_TIMEOUT = 10000;
69 69 protected final ObjectMapper jsonMapper = new ObjectMapper();
70 70
71 71 @Autowired
... ... @@ -74,6 +74,12 @@ public class RpcController extends BaseController {
74 74 @Autowired
75 75 private AccessValidator accessValidator;
76 76
  77 + @Value("${server.rest.server_side_rpc.min_timeout:5000}")
  78 + private long minTimeout;
  79 +
  80 + @Value("${server.rest.server_side_rpc.default_timeout:10000}")
  81 + private long defaultTimeout;
  82 +
77 83 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
78 84 @RequestMapping(value = "/oneway/{deviceId}", method = RequestMethod.POST)
79 85 @ResponseBody
... ... @@ -100,7 +106,8 @@ public class RpcController extends BaseController {
100 106 SecurityUser currentUser = getCurrentUser();
101 107 TenantId tenantId = currentUser.getTenantId();
102 108 final DeferredResult<ResponseEntity> response = new DeferredResult<>();
103   - long timeout = System.currentTimeMillis() + (cmd.getTimeout() != null ? cmd.getTimeout() : DEFAULT_TIMEOUT);
  109 + long timeout = cmd.getTimeout() != null ? cmd.getTimeout() : defaultTimeout;
  110 + long expTime = System.currentTimeMillis() + Math.max(minTimeout, timeout);
104 111 ToDeviceRpcRequestBody body = new ToDeviceRpcRequestBody(cmd.getMethodName(), cmd.getRequestData());
105 112 accessValidator.validate(currentUser, Operation.RPC_CALL, deviceId, new HttpValidationCallback(response, new FutureCallback<DeferredResult<ResponseEntity>>() {
106 113 @Override
... ... @@ -109,7 +116,7 @@ public class RpcController extends BaseController {
109 116 tenantId,
110 117 deviceId,
111 118 oneWay,
112   - timeout,
  119 + expTime,
113 120 body
114 121 );
115 122 deviceRpcService.processRestApiRpcRequest(rpcRequest, fromDeviceRpcResponse -> reply(new LocalRequestMetaData(rpcRequest, currentUser, result), fromDeviceRpcResponse));
... ...
... ... @@ -54,6 +54,13 @@ server:
54 54 customer:
55 55 enabled: "${TB_SERVER_REST_LIMITS_CUSTOMER_ENABLED:false}"
56 56 configuration: "${TB_SERVER_REST_LIMITS_CUSTOMER_CONFIGURATION:50:1,1000:60}"
  57 + server_side_rpc:
  58 + # Minimum value of the server side RPC timeout. May override value provided in the REST API call.
  59 + # Since 2.5 migration to queues, the RPC delay depends on the size of the pending messages in the queue,
  60 + # so default UI parameter of 500ms may not be sufficient for loaded environments.
  61 + min_timeout: "${MIN_SERVER_SIDE_RPC_TIMEOUT:5000}"
  62 + # Default value of the server side RPC timeout.
  63 + default_timeout: "${DEFAULT_SERVER_SIDE_RPC_TIMEOUT:10000}"
57 64
58 65 # Zookeeper connection parameters. Used for service discovery.
59 66 zk:
... ...