Thinking about this a little more, the real problem seems to be that we hang onto the request object in DelayedProduce until we send out the response. There are 2 reasons for this -
1. The request latency metrics are part of the request object. These need to be updated when the response is created.
2. To send out the response, we need the selector key, which is inside the request object.
To handle delayed produce requests without hanging onto the produce request data, we will need to -
1. Remove the request object from DelayedProduce
2. Pass in the selector key into DelayedProduce
3. Define the request metrics in a separate object and remove those from the Request object. Pass in the new RequestMetrics object into DelayedProduce
Since this requires changing the DelayedRequest object as well, it will affect all requests. My guess is that this refactoring is not that big of a change, but I could be wrong.