Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1883, MultipartMixed grows cache indefinitely #1887

Merged
merged 2 commits into from
Sep 22, 2020

Conversation

mikepizzo
Copy link
Member

Issues

This pull request fixes issue #1883

Description

The process of matching a formatter to a media type can be expensive, so we cache the results of a lookup in our MediaTypeCache. Unfortunately, since the key for this cache is the content type, each new content type is a separate entry in the cache.

The multipart/mixed mime type, used for batch, has a required boundary parameter, expressed as part of the media type in the content-type header, which may be set to any random value.

Some clients have fixed values for these, but it's not uncommon to use a guid.

Because a guid makes each content-type unique, the cache size grows unbounded.

The boundary isn't needed to look up the formatter, so can safely be removed from the cache lookup key.

Also fixed apparent misunderstanding in the code of the size parameter passed to the concurrent dictionary constructor. It is not a max size, but an initial size for the cache.

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

@mikepizzo mikepizzo force-pushed the MultipartMediaTypePerfFix branch from d41d2ee to 103c685 Compare September 18, 2020 03:49
@mikepizzo mikepizzo force-pushed the MultipartMediaTypePerfFix branch from 103c685 to f0a6531 Compare September 18, 2020 16:45
@mikepizzo mikepizzo requested a review from xuzhg September 18, 2020 19:04
@mikepizzo mikepizzo added P1 performance Ready for review Use this label if a pull request is ready to be reviewed labels Sep 18, 2020
@mikepizzo mikepizzo added this to the 7.7.2 milestone Sep 18, 2020
/// <returns></returns>
private static string RemoveBoundary(string contentTypeName)
{
if (contentTypeName.StartsWith("multipart", StringComparison.OrdinalIgnoreCase))
Copy link
Member

@xuzhg xuzhg Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json batch also has the "mulitpart"? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No; json uses application/json, which does not have a boundary parameter.

The boundary issue is specific to multipart/mixed, which uses a "boundary" mime type parameter to distinguish requests within the multipart/mixed batch payload.


In reply to: 492449803 [](ancestors = 492449803)

@mikepizzo mikepizzo requested a review from xuzhg September 22, 2020 03:53
{
// our formatters don't care about parameters for multipart, so just strip them all out for simplicity
int parameter = contentTypeName.IndexOf(';');
if (parameter > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume there will be only 1 ';' in the string, so rather than index and then substring, can we do in 1 pass? may be by using a stringbuilder

@mikepizzo mikepizzo merged commit 2bae48b into OData:master Sep 22, 2020
@mikepizzo mikepizzo deleted the MultipartMediaTypePerfFix branch September 22, 2020 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 performance Ready for review Use this label if a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants