2

i am trying to send a audio file(wav) from a IoT Device to Eventhub. As Eventhub has size restriction of 64Kb per message ,each message is chunked into a 7kb byte array and sent to Eventhub. i am trying to achieve maximum send rate [not crossing the threshold] from client.

Recording a live audio , save it in file stream and chunk it for sending. i avoided this part with custom stream implementation

public class CustomAudioStream : IRandomAccessStream{
    public IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)
        {
            return AsyncInfo.Run<uint, uint>((token, progress) =>
             {
                 return Task.Run(() =>
                 {
                     using (var memoryStream = new MemoryStream())
                     {
                         using (var outputStream = memoryStream.AsOutputStream())
                         {
                             outputStream.WriteAsync(buffer).AsTask().Wait();

                             var byteArray = memoryStream.ToArray();

                             //bytes are ready to send from here 
                             ChunkedEventSender(this, byteArray);
#if DEBUG
                             Debug.WriteLine("Array Length:  " + byteArray.Length + "    MemoryStream length:" + memoryStream.Length);
#endif 
                             return (uint)memoryStream.Length;
                         }
                     }
                 });
             });
        }
   }

But i am not able to send the byte at same speed here with REST implementation. for Sending i am using a third party wrapper so i can't do at that side.

But i can span thread to make application responsive while interacting so i use

 Task.Factory.StartNew(()=>{ 
          BackgroundSender(byte[data]);
        });

i don't want to wait for Task to complete neither the outcome of Task.but when i do this most of the my request are getting "Request Timed out" and Application is getting stuck because of those request.

Is there anyway i can make application responsive without blocking the thread.


Edit: Currently Applied Parallel.Invoke and not loosing a single message and application is also responsive but sending drop drastically to 2-3 message/Second

Should i switch to Multi Thread model rather than using Async. Found Simlar Question like this Is async HttpClient from .Net 4.5 a bad choice for intensive load applications?

Community
  • 1
  • 1
joshua
  • 2,371
  • 2
  • 29
  • 58
  • `Parallel.Invoke` is multithreaded ... ?? –  Sep 10 '15 at 08:41
  • No its Not Like that, – joshua Sep 10 '15 at 08:43
  • Please read [the documentation on `Parallel.Invoke`](https://msdn.microsoft.com/en-us/library/system.threading.tasks.parallel.invoke.aspx): *Executes each of the provided actions, possibly in parallel.* –  Sep 10 '15 at 08:47
  • As i said it not exactly managed multithreaded environment.it will execute function on another thread in parllel if possible. i am looking for at least 10k request processing in less than a second , Which its not giving me. – joshua Sep 10 '15 at 09:06
  • *i am looking for at least 10k request processing in less than a second* 1) Why? 2) Sending? 3) Receiving? 4) Don't you think that outgoing ports will be a bottleneck (if turnaround timing is greater than a second...)? 5) Is there a way for bulk transactions? –  Sep 10 '15 at 09:09
  • Why 10K , cause i am getting byte data at that burst. and i have to pass at same burst cause its media file if i want to reconstruct stream from bytes at other end. Yes Agree with you on bottleneck but the request duration is very short lived ~1-3 sec.so i won't be facing on client end . i hope that – joshua Sep 10 '15 at 09:25
  • So this is a perfect example for an [XY-Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)! Reconstructing the stream on the other end also requires the same order of the chunks ... And this is something I doubt you will achieve! So instead of sending chunks, is there a chance to open a stream and continuously write to it? Anyway, I strongly believe that you should rephrase your question to better match the underlying problem! –  Sep 10 '15 at 09:28
  • 1
    Hahah, May Be.... Actually i trying send to send microphone data on eventhub. When microphone is got activated i am not waiting for it write in a file,rather a custom implemented writeasync and sending byte as soon i am getting them. – joshua Sep 10 '15 at 09:35
  • 1
    only i was trying to avoid write time and again conversion to bytes. and yeah there 64K size restriction also on event hub – joshua Sep 10 '15 at 09:36

2 Answers2

0

You are being throttled by azure eventhub. Calculate your total ingress and egress and select the required number of throughput.

Each throughput unit entitles the following capabilities: 1 MB/s Ingress, 2 MB/s egress, and up to 84 GB of event storage. Go to the scale tab in the service bus namespace and increase throughput unit as necessary. enter image description here

Musfiqur rahman
  • 749
  • 4
  • 12
0

"Request timed out" doesn't necessarily mean you are being throttled I guess. I'd look for the detail property and check the error code . If you see 50002 as the error code, then that means you are throttled and you might increase the TU as necessary. FYI, a single TU supports up to a 1000 events per second.

Hope this helps!

neolursa
  • 432
  • 2
  • 6