Duplicating traffic for load testing

Hi community. I’ve searched for information on how to do this and come up empty.

Goal: We are evaluating a new origin server and we’d like to load test it before deployment.

Request: Ideally, we’d like to use Cloudflare to duplicate 100% of traffic requests to server A and route them to server B. But all server B responses would be ignored; only server A responses are returned by Cloudflare to the end user. Server B takes all the load and makes responses, but those responses are not sent to the user.

I see many ways to use Cloudflare as a load balancer between A and B, but I don’t see a way to duplicate requests to B and ignore the response.

Are there any articles discussing this?

I can’t think of an obvious way to accomplish this using any options in Cloudflare, but you could write a worker to make the appropriate calls.

You can do this with a Worker…

Fiddle with and try this untested code:


addEventListener('fetch', event => {
    console.log("****** START ******")
  event.respondWith(getFinalResponse(event.request))
})

async function getFinalResponse(request) {
    
    console.log("Fetching the server B's response...")
    
    var newURL = new URL(request.url)
    newURL.host = 'myserver.mydomain.com'
    let responseB = fetch(newURL, request)
	
    console.log("Done.")
    
	
	console.log("Fetching the server A's response...")
    
	let responseA = await fetch(request.url, request)
	
    console.log("Done.")
    
    return responseA
}

I’m not sure about how concurrency works in this case. The first call does not use await, so supposedly it will send a request to both of your servers simultaneously and not wait for the Server B’s response.

2 Likes

If you’re testing a new origin, then more likely you’re concerned about CF CDN cache miss requests that hit the origin? If so on your live origin if it’s nginx server based, you can use nginx mirror module to replicate requests to another server Module ngx_http_mirror_module

location / {
    mirror /mirror;
    proxy_pass http://backend;
}

location = /mirror {
    internal;
    proxy_pass http://test_backend$request_uri;
}

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.