0

I have method which looks like this:

     [HttpPost]
     public async Task<ActionResult> ConvertWav(int id)
     {
       using (var c = new DbEntities())
           {
              var converter = new FFMpegConverter();
              //code which converting some files from the path which the take from the DB 
              //and put it in the local directory
           }
     }

It's simple ASP.NET web application, which converting files by id from the table in DB. The table also has "dest_path" and "input_path" fields. Table contains just a path to local files. For example D:/example/file.mp3

But when it start converting, % of CPU time which converter using is very tiny. Less that 0,1% of all capability. When I starting a few converter operations (sending a few requests), it becomes even less. enter image description here

I tried using Web Garden but had the same result. How can I increase CPU usage for my requests? Full code: https://codeshare.io/7XMec

kkost
  • 3,640
  • 5
  • 41
  • 72
  • I am not getting why you are worried that your CPU usage is less. Is it is because your application is not copying files fast enough? – Martin Feb 01 '16 at 01:42
  • @Martin application converting files very slow. Converting going as fast, as CPU do it. That's what i meant – kkost Feb 01 '16 at 02:25
  • I/O operation really consume high CPU, its either you don't convert or you give your machine higher memory. – Dr. Stitch Feb 01 '16 at 02:41
  • @neustart47 What do you mean by "really slow"? Anyways, it seems your design is really flawed. Why are you converting multiple times the same file. If you add an output cache everything should be fast. Overall I think you should give us the whole project because its very very very very hard to debug psychically a performance problem when you don't give us the implementation, since it is the implementation that is broken. Give us a [Short, Self Contained, Correct (Compilable), Example](http://sscce.org/) – Aron Feb 01 '16 at 03:58
  • @Aron i shared already full code. Thank you for answer – kkost Feb 01 '16 at 11:09

2 Answers2

1

Psychic Debuging ACTIVATE!

Without seeing the rest of the code, it is very likely that your issue is that you are using the Buffered I/O API with SQL Server. This means that the time to first byte on the FFMpeg process is the time to last byte on the EntityFramework process. The solution?

You need to replace all the EF and access your database via the SqlFileStream class. Then you need to pipe the data into your FFMPeg process as opposed to using files/byte arrays.

It looks like you need to use the FFMpegConverter.ConvertLiveMedia method instead of the FFMpegConverter.ConvertMedia method to achieve this. Overall you will still find that you will be probably I/O bound rather than CPU bound.

However, in future, you should get yourself a profiler to debug perf issues.

Aron
  • 15,464
  • 3
  • 31
  • 64
  • I meant, that the table have just field with path. Path looks like: D:/ex/ex.mp3. Files located locally – kkost Feb 01 '16 at 02:21
  • You should perhaps use the output stream API as well. You IIS process is stalled on waiting for the Convert process to end. – Aron Feb 01 '16 at 03:53
  • Seems like your answer is right. I will check it out. I really using converter with AWS cloud which mount as local drive by TntDrive. – kkost Feb 01 '16 at 11:26
  • I tried to using ConvertLiveMedia, but it's not working. Without any exceptions. Here is my code: https://codeshare.io/cK2wG . Why it's not working, do you know ? – kkost Feb 02 '16 at 17:54
  • That should work, however, that would not fix your problem. Given that its a local file, using the file path should be fine. However, you want to pipe the result into the response. I would advise you to pass a `BufferStream` into the output parameter of `ConvertMedia` and then return that like [this](http://stackoverflow.com/a/9549889/1808494) – Aron Feb 02 '16 at 17:58
1

Your interpretation of the symptom is completely wrong.

By using such an async action and launch the converter, it is by design to see w3wp.exe consumes almost no CPU resources, as it simply waits for that converter task to finish.

Meanwhile, it is a poor design to do long running tasks in ASP.NET as that framework was designed for simple and quick tasks with moderate timeouts. Frameworks such as SignalR can be a better option.

Web Garden will help you but won't help much under high load, as if all threads wait on the converters, the site performance will still be poor as it cannot easily spin a free thread then.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Thank you for the answer. I am not sure that SignalR will be a good solution. What should am I using for high load background process? – kkost Feb 01 '16 at 02:37
  • @neustart47 SignalR allows you to build a publisher/subscriber way, then all processing can be scheduled in a queue. Subscribers can know the end of the tasks when your SignalR server notifies them as a publisher. Tons of samples on that in the past few years. Even high load can be handled as you can reject new tasks based on queue status. Tasks can also be dispatched to other servers if you build a load balancing system behind. – Lex Li Feb 01 '16 at 02:43