views:

315

answers:

4

This is my setting: I have written a .NET application for local client machines, which implements a feature that could also be used on a webpage. To keep this example simple, assume that the client installs a software into which he can enter some data and gets some data back.

The idea is to create a webpage that holds a form into which the user enters the same data and gets the same results back as above. Due to the company's available web servers, the first idea was to create a mono webservice, but this was dismissed for reasons unknown. The "service" is not to be run as a webservice, but should be called by a PHP script. This is currently realized by calling the mono application via shell_exec from PHP.

So now I am stuck with a mono port of my application, which works fine, but takes way too long to execute. I have already stripped out all unnecessary dlls, methods etc, but calling the application via the command line - submitting the desired data via commandline parameters - takes approximately 700ms. We expect about 10 hits per second, so this could only work when setting up a lot of servers for this task.

I assume the 700m are related to the cost of starting the application every time, because it does not make much difference in terms of time if I handle the request only once or five hundred times (I take the original input, vary it slighty and do 500 iterations with "new" data every time. Starting from the second iteration, the processing time drops down to approximately 1ms per iteration)

My next idea was to setup the mono application as a remoting server, so that it only has to be started once and can then handle incoming requests. I therefore wrote another mono application that serves as the client. Calling the client, letting the client pass the data to the server and retrieving the result now takes 344ms. This is better, but still way slower than I would expect and want it to be.

I have then implemented a new project from scratch based on this blog post and get stuck with the same performance issues.

The question is: am I missing something related to the mono-projects that could improve the speed of the client/server? Although the idea of creating a webservice for this task was dismissed, would a webservice perform better under these circumstances (as I would not need the client application to call the service), although it is said that remoting is faster than webservices?

+1  A: 

I believe that remoting is not an ideal thing to use in this scenario. However your idea of having mono on server instead of starting it every time is indeed solid.

Did you consider using SOAP webservices over HTTP? This would also help you with your 'web page' scenario.

Even if it is a little to slow for you in my experience a custom RESTful services implementation would be easier to work with than remoting.

Ilya Kochetov
A: 

I could have made that clearer, but implementing a webservice is currently not an option (and please don't ask why, I didn't write the requirements ;))

Meanwhile I have checked that it's indeed the startup of the client, which takes most of the time in the remoting scenario.

I could imagine accessing the server via pipes from the command line, which would be perfectly suitable in my scenario. I guess this would be done using sockets?

Grimtron
+3  A: 

You can try to use AOT to reduce the startup time. On .NET you would use ngen for that purpoise, on mono just do a mono --aot on all assemblies used by your application.

AOT'ed code is slower than JIT'ed code, but has the advantage of reducing startup time.

You can even try to AOT framework assemblies such as mscorlib and System.

kumpera
A: 

I AOT'ed everything already, it doesn't really help, however :(

Grimtron