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

use backend http client #456

Merged
merged 14 commits into from
Nov 6, 2017
Merged

use backend http client #456

merged 14 commits into from
Nov 6, 2017

Conversation

mikz
Copy link
Contributor

@mikz mikz commented Oct 19, 2017

  • use one endpoint for backend communication
  • simplify test suite

TODO

  • cover changes in the backend client by unit tests
  • performance test

@octobot
Copy link

octobot commented Oct 19, 2017

1 Error
🚫 Please include a CHANGELOG entry.
You can find it at CHANGELOG.md.
1 Warning
⚠️ Big PR
1 Message
📖 Note, we hard-wrap at 80 chars and use 2 spaces after the last line.

Generated by 🚫 Danger

@mikz mikz force-pushed the backend-http-client branch 4 times, most recently from 2d0cc5e to 0d136f5 Compare October 20, 2017 07:44

local http_ng = require('resty.http_ng')
local user_agent = require('user_agent')
local resty_url = require('resty.url')
local resty_env = require('resty.env')

local _M = {
endpoint = resty_env.get("BACKEND_ENDPOINT_OVERRIDE")
Copy link
Contributor Author

@mikz mikz Oct 23, 2017

Choose a reason for hiding this comment

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

This should be ignoring empty string by using env.value instead.


ngx.log(ngx.INFO, 'backend client uri: ', url, ' ok: ', res.ok, ' status: ', res.status, ' body: ', res.body)

return res
end

local authorize_options = {
headers = {
['3scale-options'] = 'rejection_reason_header=1'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davidor this should be more dynamic, right? So we can have no_body for normal authrep but not for oauth calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we need that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave this for a future PR when we actually add more options to avoid adding more complexity to this PR.

location /transactions/authrep.xml {
content_by_lua_block {
ngx.header['3scale-rejection-reason'] = 'limits_exceeded';
if ngx.var['http_3scale_options'] == 'rejection_reason_header=1' then
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are we setting ngx.var['http_3scale_options']? I only see ngx.var.options = headers['3scale-options'].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davidor $http_ headers are mapped to the request headers: http://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_

@davidor davidor force-pushed the backend-http-client branch from a55a92e to faa8506 Compare October 23, 2017 15:55
@davidor
Copy link
Contributor

davidor commented Oct 23, 2017

@mikz I added a few commits on top of yours. Please let me know if you think that there's anything else we should do before benchmarking this against master.

@mikz mikz assigned davidor and unassigned mikz Oct 25, 2017
@mikz
Copy link
Contributor Author

mikz commented Oct 25, 2017

👍 good job @davidor

I think this should be good to go for the performance test.

@davidor
Copy link
Contributor

davidor commented Oct 25, 2017

I benchmarked this. I Deployed just an Apicast (authorizing without going to 3scale's backend) and another one in echo mode (as api backend) in separate machines.

The tests were performed using JMeter from an external machine. Absolute numbers are not really meaningful, as there are many factors that can affect them. I just want to focus on the comparison between this branch and its base. I used c4.xlarge aws machines, configured Apicast with 4 workers, and run JMeter for 10 minutes.

Without this PR

no

With this PR

yes

Unfortunately, this PR introduces an important performance regression.

@davidor davidor force-pushed the backend-http-client branch 3 times, most recently from 93c73a9 to d78ddf3 Compare November 2, 2017 17:13
@davidor davidor mentioned this pull request Nov 2, 2017
mikz and others added 11 commits November 2, 2017 20:19
backend using ngx.location.capture
* remove unnecessary configuration
* move authorization to config instead of var
* now there is just 1 location for contacting backend
Authreps now use the 'http_call' location.
- Deletes unused code in the Proxy module.
- Avoids defining methods with ':' when self is not necessary in the ngx
  backend of the http_ng library.
Now http_client is used instead.
gsub is not implemented in the luajit compiler. Replacing gsub with code
that can be compiled instead of interpreted will increase performance.
Avoid using regex. It's much more performant this way. Using Apicast in
echo mode, in a particular setup it went from ~3.5k rps to ~5k.
@davidor davidor force-pushed the backend-http-client branch from d78ddf3 to 4efa022 Compare November 2, 2017 19:19
@davidor
Copy link
Contributor

davidor commented Nov 3, 2017

Update: the last 3 commits increase the performance, but it's still not on par with the performance of the master branch. It's important to note that this benchmark is only testing cpu as Apicast is acting both as auth backend, and api backend. This means that the difference might not be noticeable in a real-case scenario where the api and the auth backend are in different machines.

PR:
pr

Master:
master

I found that the abstractions in the http_ng/headers module are costly. I did a quick test removing most of the code in that module and got an extra ~1k rps. Maybe we should evaluate whether we need all what that module provides.

Also, harcoding the result of the merge operation in the http_ng module gives around ~450 rps more. So that's also something that we could optimize.

@mikz mikz changed the title [wip] use backend http client use backend http client Nov 3, 2017
@mikz
Copy link
Contributor Author

mikz commented Nov 3, 2017

👍

The members of a 'headers' instance have more methods and make the merge
operation more costly. Also, we do not need to instantiate 'headers'
here, because it's done later anyway when calling http.request.new().
This also makes the code more readable in my opinion, because we only
need to deal with header instances in one class instead of in two like
we do now.

I have benchmarked this and it increases performance a bit when Apicast
acts both as auth backend and api backend (cpu workload).
@mikz mikz merged commit 031de57 into master Nov 6, 2017
@mikz mikz deleted the backend-http-client branch November 6, 2017 09:02
mikz added a commit that referenced this pull request Nov 6, 2017
@mikz
Copy link
Contributor Author

mikz commented Nov 6, 2017

Added changelog entry in 0108fb2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants