-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
On-demand copy for Response.Request.Body #2395
Comments
The predominant problem with this it will require quite a big refactor, making access to everything slower to get the benefit only in the cases that it's useful. Additionally, golang will return the body as I would argue that given all of the above this likely will not have that good of a performance improvement. The best case scenario is that literally nothing is ever requested, which is kind of the most likely scenario. But in all other cases it will be worse(by some amount). Arguably something like #845 will be much easier to implement and likely will have better final performance. IMO (as I tried to elude in #2311) the correct fix for those are to move towards an API that can make all of these problems ... not a problem ;). Like in this case unless you request the body (through some way) we won't actually keep it. We also probably should require the whole body in order to make the request and then also not keep it around. This of course means a lot of work and a smaller temporary workaround might be a good stop gap solution, as long as it isn't very complex to implement - like this one IMO. |
@mstoykov, this is about the copy of the request body that is saved in Moreover, this probably is actually a bug, not just very inefficient: k6/lib/netext/httpext/request.go Line 145 in 737dfa7
For binary bodies, this will likely mangle them... So, I am fine with trying to use a proxy. I am also fine with making a minor breaking change and actually make the property return a lazy-loaded |
@na-- Do you mean totally dropping the export default function () {
const url = 'http://test.k6.io/login'
const payload = JSON.stringify({
email: 'aaa',
password: 'bbb',
})
const params = {
headers: {
'Content-Type': 'application/json',
},
}
let res = http.post(url, payload, params)
console.log(res.request.headers)
} |
No, I mean the exact same k6/js/modules/k6/http/request.go Lines 57 to 67 in 737dfa7
Can be threaded through the code and returned by the
Exactly what is currently returned - if technically possible, I propose no changes to anything in |
My mistake 🤦 This still doesn't really work for all cases.
And an example that I kind of give in #2311 (but not as heads on as I remember): const data = new ArrayBuffer(8);
const view = new Int32Array(buffer);
view[0] = 20;
let response1 = http.post(url, data)
// some more code
view[2] =23;
let response2 = http.post(url, data)
// some more code
// What is the value of `response1.request.body` here? Also while we still don't have asynchronous code - we soon should be able to have one in which case this is even a potential race condition ...
http.asyncPromise(url, data).then(....)
view[3]=12
http.asyncPromise(url2, data).then(....)
... Again this feels like we are trying to patch the problem while IMO the problem is systemic in the API and the fix should be to move to a different API that doesn't have those problems. This also will be a really good promotion of the new API - "it works way better than the previous one" |
Ideally no, but what I said in #2395 (comment) is that I would be fine with that compromise if we couldn't implement something better, e.g. a no-copy
There is probably very little point in
Maybe, but fixing this unnecessary and wrong string copying won't make all of these efforts worse (esp. if the |
Closing as we prefer to directly address the core problem in the new HTTP API. |
As part of #2311 investigation and as previously reported in #1931 (comment) the
Response.Request.Body
field as astring
type requires executing a dedicated copy for each request.This problem creates noise for better profiling of #2311 and it should be required from any solution applied to #2311.
k6/lib/netext/httpext/request.go
Lines 52 to 56 in 737dfa7
Suggestion
The current string field is really required only when the JS property is accessed directly. The proposal is to switch to
[]byte
and generate the string only on-demand when the property is accessed from JS. It should allow reusing the original slice used on the HTTP parsing.The copy should be executed in the Get function for a
goja.Proxy
object. The Proxy wraps thek6/http.Response
object.Example
The text was updated successfully, but these errors were encountered: