A Quick F# Load Test Script

April 23, 2024    Development .Net F#

A Quick F# Load Test Script

Here’s a quick way to hit your api with a lot of requests in parallel using F# .

Requirements

  • FsHttp
  • A way to run F#
    • VS Code is helpful with the F# Ionide Extension
      • create a .fsx file in VS Code, highlight all and alt-enter or click the play button

Code

#r "nuget: FsHttp"
open FsHttp

[|1..1000|]
 |> Array.Parallel.map (fun x ->
       (x, http {
           GET "https://{your-url}/api/"
           //AuthorizationBearer ""
           // add a custom header if you need: this is needed for Azure Functions header "X-Functions-Key" ""
           body 
           jsonSerialize x
       }
       |> Request.send)
   ) 
   |> Seq.iter (fun (org, response) -> 
       let contentValue = Response.toString (Some 9000) response
       printfn "Request: %A | Status Code: %A | Response Content: %A" org response.statusCode contentValue
   )


Watch the Story for Good News
I gladly accept BTC Lightning Network tips at [email protected]

Please consider using Brave and adding me to your BAT payment ledger. Then you won't have to see ads! (when I get to $100 in Google Ads for a payout, I pledge to turn off ads)

Use Brave

Also check out my Resources Page for referrals that would help me.


Swan logo
Use Swan Bitcoin to onramp with low fees and automatic daily cost averaging and get $10 in BTC when you sign up.