kubemq-io / kubemq-CSharp

C# Library for KubeMQ server
MIT License
30 stars 8 forks source link

Weird Behaviour of Transaction.Receive #11

Closed francotiveron closed 1 year ago

francotiveron commented 2 years ago

Transaction.Receive has highly variable execution times. When executed in a loop with queue empty, the following cycle repeats:

1) A number of calls return immediately 2) Then a call takes a second

See the following F# test code and the relative log result

open KubeMQ.SDK.csharp
open System
open System.Diagnostics

let queue = "q-1"
let url = "localhost:50000"

let cl = Queue.Queue(queue, "client", url)
cl.AckAll(1) |> ignore
let t = cl.CreateTransaction()
let sw = Stopwatch()

module M =
    let rec loop i = async {
        sw.Restart()
        let rsp = t.Receive(0, 0)
        sw.Stop()
        if sw.ElapsedMilliseconds < 500L then
            printf "%d/%dms " i (int(sw.ElapsedMilliseconds))
        else
            printfn "\n"
            printfn "%d/%dms <- WHY?\n" i (int(sw.ElapsedMilliseconds))
        return! loop (i + 1)
    }

M.loop 0 |> Async.Start

Console.ReadLine() |> ignore

0/1023ms <- WHY? 1/1003ms <- WHY?

2/0ms 3/0ms 4/0ms 5/0ms 6/0ms 7/0ms 8/0ms 9/0ms 10/0ms 11/0ms 12/0ms 13/0ms 14/0ms 15/0ms 16/0ms 17/0ms 18/0ms 19/0ms 20/0ms 21/0ms 22/0ms 23/0ms 24/0ms 25/0ms 26/0ms 27/0ms 28/0ms 29/0ms 30/0ms 31/0ms 32/0ms 33/0ms 34/0ms 35/0ms 36/0ms 37/0ms 38/0ms 39/0ms 40/0ms 41/0ms 42/0ms 43/0ms 44/0ms 45/0ms 46/0ms 47/0ms

48/1002ms <- WHY?

49/0ms 50/0ms 51/0ms 52/0ms 53/0ms 54/0ms 55/0ms 56/0ms 57/0ms 58/0ms 59/0ms 60/0ms 61/0ms 62/0ms 63/0ms 64/0ms 65/0ms 66/0ms 67/0ms 68/0ms 69/0ms 70/0ms 71/0ms 72/0ms 73/0ms 74/0ms 75/0ms 76/0ms 77/0ms 78/0ms 79/0ms 80/0ms 81/0ms 82/0ms 83/0ms 84/0ms 85/0ms 86/0ms 87/0ms 88/0ms 89/0ms 90/0ms 91/0ms 92/0ms 93/0ms 94/0ms 95/0ms 96/0ms 97/0ms 98/0ms 99/0ms 100/0ms 101/0ms 102/0ms 103/0ms 104/0ms 105/0ms 106/0ms

107/1003ms <- WHY?

108/0ms 109/0ms 110/0ms 111/0ms 112/0ms 113/0ms 114/0ms 115/0ms 116/0ms 117/0ms 118/0ms 119/0ms 120/0ms 121/0ms 122/0ms 123/0ms 124/0ms 125/0ms 126/0ms 127/0ms 128/0ms 129/0ms 130/0ms 131/0ms 132/0ms 133/0ms 134/0ms 135/0ms 136/0ms 137/0ms 138/0ms 139/0ms 140/0ms 141/0ms 142/0ms 143/0ms 144/0ms 145/0ms 146/0ms 147/0ms 148/0ms 149/0ms 150/0ms 151/0ms 152/0ms 153/0ms 154/0ms 155/0ms 156/0ms 157/0ms 158/0ms 159/0ms 160/0ms 161/0ms

162/1002ms <- WHY?

163/0ms 164/0ms 165/0ms 166/0ms 167/0ms 168/0ms 169/0ms 170/0ms 171/0ms 172/0ms 173/0ms 174/0ms 175/0ms 176/0ms 177/0ms 178/0ms 179/0ms 180/0ms 181/0ms 182/0ms 183/0ms 184/0ms 185/0ms 186/0ms 187/0ms 188/0ms 189/0ms 190/0ms 191/0ms 192/0ms 193/0ms 194/0ms 195/0ms 196/0ms 197/0ms 198/0ms 199/0ms 200/0ms 201/0ms 202/0ms 203/0ms 204/0ms 205/0ms 206/0ms 207/0ms 208/0ms

209/1002ms <- WHY?

210/0ms 211/0ms 212/0ms 213/0ms 214/0ms 215/0ms 216/0ms 217/0ms 218/0ms 219/0ms 220/0ms 221/0ms 222/0ms 223/0ms 224/0ms 225/0ms 226/0ms 227/0ms 228/0ms 229/0ms 230/0ms 231/0ms 232/0ms 233/0ms 234/0ms 235/0ms 236/0ms 237/0ms 238/0ms 239/0ms 240/0ms 241/0ms 242/0ms 243/0ms 244/0ms 245/0ms 246/0ms 247/0ms 248/0ms 249/0ms 250/0ms 251/0ms 252/0ms 253/0ms

254/1003ms <- WHY?

255/0ms 256/0ms 257/0ms 258/0ms 259/0ms 260/0ms 261/0ms 262/0ms 263/0ms 264/0ms 265/0ms 266/0ms 267/0ms 268/0ms 269/0ms 270/0ms 271/0ms 272/0ms 273/0ms 274/0ms 275/0ms 276/0ms 277/0ms 278/0ms 279/0ms 280/0ms 281/0ms 282/0ms 283/0ms 284/0ms 285/0ms 286/0ms 287/0ms 288/0ms 289/0ms 290/0ms 291/0ms 292/0ms 293/0ms 294/0ms 295/0ms 296/0ms 297/0ms 298/0ms 299/0ms 300/0ms 301/0ms 302/0ms 303/0ms 304/0ms 305/0ms

306/1002ms <- WHY?

307/0ms 308/0ms 309/0ms 310/0ms 311/0ms 312/0ms 313/0ms 314/0ms 315/0ms 316/0ms 317/0ms 318/0ms 319/0ms 320/0ms 321/0ms 322/0ms 323/0ms 324/0ms 325/0ms 326/0ms 327/0ms 328/0ms 329/0ms 330/0ms 331/0ms 332/0ms 333/0ms 334/0ms 335/0ms 336/0ms 337/0ms 338/0ms 339/0ms 340/0ms 341/0ms 342/0ms 343/0ms 344/0ms 345/0ms 346/0ms 347/0ms 348/0ms 349/0ms 350/0ms 351/0ms 352/0ms 353/0ms 354/0ms 355/0ms

kubemq commented 1 year ago

Please use the QueueStream implementation