Skip to content

Instantly share code, notes, and snippets.

@joebo

joebo/stress.l Secret

Created August 19, 2016 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joebo/fa91b263fece8adc3c18186fc1d6c50b to your computer and use it in GitHub Desktop.
Save joebo/fa91b263fece8adc3c18186fc1d6c50b to your computer and use it in GitHub Desktop.
(off *RequestTimeTaken)
(setq *Host "www.notreal.com")
(setq *BaseURL "/app/")
(setq *Path "//c/path")
(setq *UserCount 1100)
(setq *UserList (mapcar '((X) (pack "user" X)) (range 1 *UserCount)))
# helper to reload under win pil
(de r () (script (pack *Path "fork.l")))
# builds url
(de build-url (Table UID) (pack *BaseURL "&table=" Table "&uid=" UID))
# makes html request
(de get-http (Host Url)
(chop (pack (make
(let (Sock (connect Host 80) BeforeTime (stamp))
(out Sock (prinl "GET " Url " HTTP/1.0\n\n"))
(in Sock (until (eof) (link (line))))
(close Sock)
(setq *RequestTimeTaken (pack BeforeTime " " (stamp))))))))
# splits JSON to pull out important parts
(de json-get (Data Key)
(make
(for (V (split Data " " "\"") V)
(when (= (pop 'V) Key)
(link (pack (caddr V )))))))
(de work ()
(msg *Pid " " V)
(out
(pack "+tmp/" *Pid ".txt")
(let (User (car (nth *UserList (rand 1 *UserCount))) Data NIL Customers NIL CustomerNumber NIL Products NIL ProductCode NIL)
(msg "Requesting Page1 for " User)
(setq Data (get-http *Host (build-url "Page1" User)))
(prinl *RequestTimeTaken ", Page1," CustomerNumber "^J^M")
(setq Customers (json-get Data '`(chop "CustomerNumber")))
(setq CustomerNumber (car (nth Customers (rand 1 (length Customers)))))
(wait 3000)
(msg "Requesting Page2 for " CustomerNumber)
(setq Data (get-http *Host
(pack (build-url "Page2" User)
"&param1=all&param2=" CustomerNumber)))
(prinl *RequestTimeTaken ", Page2," CustomerNumber "^J^M")
(wait 3000)
(setq Products (json-get Data '`(chop "ProductCode")))
(setq ProductCode (car (nth Products (rand 1 (length Products)))))
(msg "Requesting Page3 for " CustomerNumber " Product " ProductCode)
(setq Data (get-http *Host
(pack (build-url "Page3" User)
"&param1=" ProductCode "&param2=" CustomerNumber)))
(prinl *RequestTimeTaken ",Dashboard," CustomerNumber "," ProductCode "^J^M"))))
(de go ()
(for I (range 0 50)
(wait 100)
(T (unless (fork)
(detach)
(seed I)
(task -20000 (* I 1000) V 0 (work)) ) )))
(println *Pid " DONE!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment