Skip to content

Negative caching shouldn't happen on 400 response (#396) - #2031

Closed
persiaAziz-zz wants to merge 1 commit into
apache:masterfrom
persiaAziz-zz:NegativeCaching
Closed

persiaAziz-zz wants to merge 1 commit into
apache:masterfrom
persiaAziz-zz:NegativeCaching

Conversation

@persiaAziz-zz

@persiaAziz-zz persiaAziz-zz commented May 31, 2017 •

Copy link
Copy Markdown
Contributor
  • adds a vector containing the status code for which the response will be cached with negative caching enabled.
  • binary search added for ts/Vec
  • test program to test the binary search


switch (s->hdr_info.server_response.status_get()) {
case HTTP_STATUS_NO_CONTENT:
case HTTP_STATUS_USE_PROXY:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmmm, I guess I don't understand what was wrong with the old switch. Compilers can typically optimize that into very efficient code I think.

Comment thread proxy/http/HttpConfig.cc
c.codeNegCache.add(HTTP_STATUS_NO_CONTENT);
c.codeNegCache.add(HTTP_STATUS_USE_PROXY);
c.codeNegCache.add(HTTP_STATUS_FORBIDDEN);
c.codeNegCache.add(HTTP_STATUS_NOT_FOUND);

@zwoop zwoop May 31, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Honestly, since the number of status codes are limited, a standard C array with 1000 bool elements would be easier, and definitely faster.

ink_zero(codeNegCache, sizeof(codeNegCache);
codeNegCache[HTTP_STATUS_NO_CONTENT] = true;
codeNegCache[HTTP_STATUS_USE_PROXY] = true;

etc. Then the check if a particular status code is cacheable is O(1). Yeh, so we waste 1KB (give or take) of RAM, but I bet all this code makes up for that anyways :-).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As amc pointed out, you could even make the array smaller since, 400-599 (so two hundred bytes).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can make it 25 bytes if you use a bitmap.

Comment thread lib/ts/Vec.h
else
return bin_search(s, mid - 1, lt, eq, item);

return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should probably remove this, to make sure the compiler can tail recurse this for sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That will likely create a coverity issue as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We wouldn't need this if we replace the vec in this patch with array. I can make a separate patch for the binary search if you think this might be useful.

Comment thread proxy/http/HttpConfig.cc
c.codeNegCache.add(HTTP_STATUS_NO_CONTENT);
c.codeNegCache.add(HTTP_STATUS_USE_PROXY);
c.codeNegCache.add(HTTP_STATUS_FORBIDDEN);
c.codeNegCache.add(HTTP_STATUS_NOT_FOUND);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As amc pointed out, you could even make the array smaller since, 400-599 (so two hundred bytes).

Comment thread proxy/http/HttpConfig.cc
params->synthetic_port = m_master.synthetic_port;

m_id = configProcessor.set(m_id, params);
params->codeNegCache = m_master.codeNegCache;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This was unclear to me too, but amc told me that the intent was to make this configurable (but it obviously isn't in this patch). So ignore my comment on the switch statement, it would not suffice if you plan on making this vector / array configurable.

@SolidWallOfCode

Copy link
Copy Markdown
Member

I think when this was started we hadn't moved to eleventy yet. In view of that I'd recommend

  • Don't use Vec, use std::vector.
  • With std::vector you get std::binary_search rather than writing your own.
  • Alternatively, in line with @zwoop's suggestion, you could use std::bitset which would take less than 80 bytes for 0-599 and be quite fast.

Finally, I thought the goal of this was to be able to configure the negative cache enabled list.

@persiaAziz-zz

Copy link
Copy Markdown
Contributor Author

@SolidWallOfCode @zwoop yah this patch is pretty old. Array sounds like a better idea. I will update this accordingly.

@PSUdaemon

Copy link
Copy Markdown
Contributor

Just reading all the comments in order, and I agree with @SolidWallOfCode. Use std::bitset.

@persiaAziz-zz persiaAziz-zz self-assigned this Jun 1, 2017
@persiaAziz-zz persiaAziz-zz added this to the 8.0.0 milestone Jun 1, 2017
@bryancall bryancall added the WIP label Jul 21, 2017

@dragon512 dragon512 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a test for this

@persiaAziz-zz

Copy link
Copy Markdown
Contributor Author

will resurrect later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants