Created
October 4, 2012 09:03
-
-
Save michael-newton-15below/3832369 to your computer and use it in GitHub Desktop.
Service stress testing with EasyNetQ and F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Learn more about F# at http://fsharp.net | |
open EasyNetQ | |
open EasyNetQ.Loggers | |
open FifteenBelow.WindowsServices.Messages | |
open FifteenBelow.WindowsServices | |
open FifteenBelow.Utilities.Configuration | |
open FifteenBelow.Configuration.AppConfig | |
let mutable logger = new ConsoleLogger() | |
logger.Debug <- false | |
logger.Info <- false | |
let bus = RabbitHutch.CreateBus("host=localhost", logger) | |
let mutable auditReport1 = new AuditReport() | |
auditReport1.Message <- "Hello from F#" | |
auditReport1.LogLevel <- EnumTypes.log4netLevels.DEBUG | |
auditReport1.FunctionName <- "Tester1" | |
auditReport1.ReportCode <- 6501 | |
auditReport1.Occurrence <- System.DateTime.UtcNow | |
auditReport1.SourceServer <- "MyMachine" | |
auditReport1.SourceApplication <- "TestHarness" | |
let mutable auditReport2 = new AuditReport() | |
auditReport2.Message <- "Oh noes, I'm F# pretending to have gone wrong!" | |
auditReport2.LogLevel <- EnumTypes.log4netLevels.ERROR | |
auditReport2.FunctionName <- "Tester2" | |
auditReport2.ReportCode <- 6500 | |
auditReport2.Occurrence <- System.DateTime.UtcNow | |
auditReport2.SourceServer <- "MyMachine" | |
auditReport2.SourceApplication <- "TestHarness" | |
let mutable appInfo = new ApplicationInformation() | |
appInfo.ApplicationName <- "TestHarness" | |
appInfo.ApplicationShortName <- "Test" | |
appInfo.EmailFromAddress <- "from@example.com" | |
appInfo.HeartbeatInterval <- 0 | |
appInfo.ApplicationID <- -1 | |
appInfo.ConfigConnectionString <- "Nope" | |
appInfo.TaskTimeToLive <- 20 | |
let sendMessages taskName report count = | |
let mutable message = new CreateAuditReportMessage() | |
message.ApplicationStructure <- appInfo | |
message.AuditReportObject <- report | |
let rec sendMessage message i = | |
using (bus.OpenPublishChannel()) (fun publishChan -> publishChan.Publish message) | |
if i % 1000 = 0 then printf "%s" taskName | |
if i < count then | |
sendMessage message (i + 1) | |
sendMessage message 1 | |
taskName + " complete" | |
let sendErrors taskName report count = | |
let mutable message = new CreateErrorReportMessage() | |
message.ApplicationStructure <- appInfo | |
message.AuditReportObject <- report | |
let rec sendMessage message i = | |
using (bus.OpenPublishChannel()) (fun publishChan -> publishChan.Publish message) | |
if i % 1000 = 0 then printf "%s" taskName | |
if i < count then | |
sendMessage message (i + 1) | |
sendMessage message 1 | |
taskName + " complete" | |
do | |
let task1 = async { return sendMessages "1" auditReport1 10000 } | |
let task2 = async { return sendMessages "2" auditReport1 10000 } | |
let task3 = async { return sendErrors "3" auditReport2 10000 } | |
let task4 = async { return sendErrors "4" auditReport2 10000 } | |
let startTime = System.DateTime.UtcNow | |
Async.RunSynchronously (Async.Parallel [task1;task2;task3;task4]) |> printfn "%A" | |
let endTime = System.DateTime.UtcNow | |
printfn "Done, taking %A" (endTime - startTime) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment