harshkha3417 opened a new pull request, #7841:
URL: https://github.com/apache/shenyu/pull/7841

   ## What is the purpose of the change
   
   Fixes #7831.
   
   In `GrpcPlugin.doExecute()`, 
`GsonUtils.getGson().fromJson(metaData.getRpcExt(), GrpcExtInfo.class)` was 
executed on every request. Even though `MetaData` is cached and unchanged 
across requests, JSON deserialization occurred redundantly on the hot path.
   
   This pull request optimizes the execution path by caching the parsed 
`GrpcExtInfo` representation in `ApplicationConfigCache` and reusing it across 
requests.
   
   ## Brief changelog
   
   - **Extracted `GrpcExtInfo`**:
     - Moved `GrpcExtInfo` into its own class under 
`org.apache.shenyu.plugin.grpc.cache.GrpcExtInfo` with equals/hashCode and 
default fallback values (`timeout = 5000`, `methodType = UNARY`).
   - **Cached `GrpcExtInfo` in `ApplicationConfigCache`**:
     - Added bounded `Cache<String, CachedGrpcExtInfo> grpcExtCache` in 
`ApplicationConfigCache`.
     - Added `obtainGrpcExtInfo(final MetaData metaData)` which fetches from 
cache by metadata key (falling back to parse & store if not present or if 
`rpcExt` changed).
     - Handles null, blank, or JSON-null values safely by falling back to 
immutable default settings.
     - Added `cacheGrpcExtInfo(final MetaData metaData)`, 
`invalidateGrpcExtInfo(final MetaData metaData)`, and `cleanGrpcExtInfo()` for 
cache management.
   - **Added `GrpcMetaDataHandler`**:
     - Implemented `MetaDataHandler` for `RpcTypeEnum.GRPC` to subscribe to 
metadata events (`handle`, `remove`, `refresh`) and keep 
`ApplicationConfigCache` in sync.
     - Registered `GrpcMetaDataHandler` bean in `GrpcPluginConfiguration`.
   - **Preserved Per-Request Deadline Freshness**:
     - `CallOptions.DEFAULT.withDeadlineAfter(extInfo.getTimeout(), 
TimeUnit.MILLISECONDS)` remains computed dynamically per request in 
`GrpcPlugin.doExecute()`, ensuring deadlines are evaluated relative to request 
dispatch time.
   - **Tests**:
     - Added unit tests in `ApplicationConfigCacheTest` verifying parsing, 
reuse across identical calls, defaults fallback, updates on metadata `rpcExt` 
change, and cache invalidation/cleanup.
     - Added unit tests in `GrpcMetaDataHandlerTest` verifying metadata 
handling, removal, refresh, and rpcType.
     - Added tests in `GrpcPluginTest` verifying `GrpcExtInfo` reuse across 
requests and per-request `CallOptions` deadline freshness.
     - Added test in `GrpcPluginConfigurationTest` verifying the 
`grpcMetaDataHandler` bean registration.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to