What is the best way to run ServiceStack on Linux / Mono?

On the ServiceStack website , it shows that ServiceStack can run in Mono with:

  • Xsp
  • mod_mono
  • Fastcgi
  • Console

What are these different configurations and which are preferable for mono web services?

+48
c # linux mono servicestack mod-fastcgi
Aug 30 2018-12-12T00:
source share
5 answers

Linux update

From release v4.5.2, ServiceStack now supports .NET Core, which offers significant performance and stability improvements over Mono, which are derived from a common cross-platform code base and are supported by Microsoft, which has sufficient resources, an active and responsive team. If you are currently running ServiceStack on Mono, we highly recommend switching to .NET Core to take advantage of its superior performance, stability, and top-down technology support.

Update for mono

Our recommended installation for hosting ASP.NET sites on Linux and Mono is to use nginx / HyperFastCgi. We have published a step-by-step guide on creating an Ubuntu virtual machine from scratch using the deploy / install / conf / init scripts in mono-server-config .

We no longer recommend MonoFastCGI, noting several stability and performance issues. This blog post provides a good analysis of the performance, memory usage, and stability of various ASP.NET hosting options in Mono .




Development

XSP is like VS.NET WebDev, a simple stand-alone ASP.NET WebServer written in C #. It is suitable for development or small workloads. You simply run it from the root directory of your ASP.NET ServiceStack node, which will make it available at http://localhost:8080 .

Products

For external Internet services, you usually want to host ServiceStack web services as part of a full-featured web server. The 2 most popular full-featured web servers for Linux:

Nginx

Use Mono FastCGI to host HostStStStStack hosts in Nginx .

Apache

Use mod_mono to host HostStStStStack hosts in an Apache HTTP server .

Self hosting

ServiceStack also supports self-hosting, which allows you to run ServiceStack web services on your own in a standalone console application (i.e. without a web server). This is a good idea when you do not need the services of a full-featured web server (for example, you just need to host web services inside Intranet).

By default, the same ServiceStack Console application binary works on both Windows / .NET and Mono / Linux as it is. Although, if you want, you can easily unmount your application and start as a Linux daemon, as described here . The wiki page also contains instructions for setting up your own web service to work with a reverse Nginx or Apache proxy.

Since it is great for the Heroku Concurrency model as described in their 12-factor example , self-service will be an area in which we will strive to increase support in the near future.

ServiceStack.net Nginx / Mono FastCGI Configuration

The servicestack.net website itself (including all demos) runs on Ubuntu hetzner vServer using Nginx + Mono FastCGI.

This command is used to start the FastCGI background process:

 fastcgi-mono-server4 --appconfigdir /etc/rc.d/init.d/mono-fastcgi /socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log & 

In which all applications defined in * .webapp files are located in the /etc/rc.d/init.d/mono-fastcgi folder specified using the XSP WebApp file format , for example:

ServiceStack.webapp:

 <apps> <web-application> <name>ServiceStack.Northwind</name> <vhost>*</vhost> <vport>80</vport> <vpath>/ServiceStack.Northwind</vpath> <path>/home/mythz/src/ServiceStack.Northwind</path> </web-application> </apps> 

This starts the FastCGI Mono process in the background, with which you can connect to Nginx by adding this rule to nginx.conf:

 location ~ /(ServiceStack|RedisAdminUI|RedisStackOverflow|RestFiles)\.* { root /usr/share/nginx/mono/servicestack.net/; index index.html index.htm index.aspx default.htm Default.htm; fastcgi_index /default.htm; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /usr/share/servicestack.net$fastcgi_script_name; include /etc/nginx/fastcgi_params; } 

Any route starting with /ServiceStack or /RedisAdminUI , etc. will be redirected. to the FastCGI monoserver process for processing. Some sample applications are placed this way:

For those who are interested in the full Nginx + FastCGI configuration file for servicestack.net, it is available for download .

+84
Aug 30 2018-12-12T00:
source share

During production, we use nginx with unix file sockets

We detected an error / memory leak when using socket communication with nginx, service stack and mono. It was with 500 simultaneous requests, while you were expecting a surge in CPU and memory, it was no longer returning. We did not conduct any further tests to find out where the problem is, but there is an error registered with xamarin bugzilla , which is similar to the problems we had. In fact, we tried the following, and that was enough for us.

We switched to using unix sockets with the following command options

fastcgi-mono-server4 / filename = / tmp / something.socket / socket = unix / Applications = / var / WWW /

The problem with this method is that the socket file permissions changed every time you started fastcgi-mono-server4, so you need to fix them after you run fastcgi-mono-server4! Another drawback is that on our mailboxes it could process only about 120 simultaneous requests. However, at the moment this is not a problem for us, and you can always create new processes.

Hope this helps

+19
Sep 06
source share

Disclaimer: I am the author of the HyperFastCgi server, and the author of the blog post is mentioned in ceco's answer

nginx with HyperFastCgi do the job. HyperFastCgi does not leak memory as a fastcgi single-line server and is much faster because it uses a low-level mono-API to transfer data between application domains instead of a slow mono-JIT implementation of cross-domain calls. He also has the ability to use the built-in libevent library for sockets, which is about 1.5-2 faster than the current monosystem implementation of System.Net.Sockets.

Key features of HyperFastCgi:

  • Allows you to use 3 different ways to work with sockets and cross-domain communication:
    • Managed Listener with Managed Transport (uses only managed code, asynchronous System.Net.Sockets. Slow in mono, due to slow cross-domain JIT calls)
    • Managed Listener with Combined Transport (uses async System.Net.Sockets as a listener and low-level mono API for cross-domain calls. Much faster)
    • Native Listener (uses the built-in libevent as a socket library and a low-level mono-API for making cross-domain calls. Best performance)
  • Allows several concurrent web requests: using ThreadPool, .NET 4.5 Task or Single-threading. The latter parameters are combined with the Native Listener makes the web server work like NodeJS : all requests are processed in the same thread in an asynchronous way.
  • Allows you to write simple request handlers without using System.Web at all. This increases the query processing performance by 2-2.5 times.
+6
Sep 28 '14 at 4:23
source share

There is a useful and relatively recent Mono performance blog post using ServiceStack. I thought that this could be useful for those who are going to decide how to place their services: Servicestack performance in mono .

As the saying goes: the FastCGI Mono server has a tone of memory leaks that I can confirm. I ran ab -n 100000 -c 10 http://myurl on Ubuntu Desktop 14.04 using Mono 3.2.8 and Nginx 1.4.6 and FastCGI Mono Server 3.0.11 and a service written using ServiceStack 3.9.71. I donโ€™t think it matters which version of ServiceStack I am using, since FastCGI Mono Server is a leaking bit. He ate all the available memory - only about 1 GB out of 2 GB.

In addition, the performance of Nginx + FastCGI Mono Server is poor , at least in comparison with other solutions. My REST test service had about 275 requests per second. The author of the blog reviewed the FastCGI Mono Server code and decided to write his own implementation. For some reason it does not work, although at least on my machine.

So, I think you should not use FastCGI Mono Server. If you do not want to reload your box often.

Since this post is mostly negative, I have to say what are my intentions regarding the placement of my services. I will probably go to a separate hosting with AppHost, inheriting AppHostHttpListenerLongRunningBase for Nginx. Using the same trial REST service above, I get about 1100 requests per second. The best news is that the process did not have any obvious leaks, I tested it with about 1,000,000 requests and the process consumed <100 MB of RAM.

PS I am not the author of the blog post :)

+4
Apr 30 '14 at 9:16
source share

evhttp-sharp - http server with host for NancyFx

https://github.com/kekekeks/evhttp-sharp

Very fast, almost 4 times faster than nancy-libevent2.

http://www.techempower.com/benchmarks/#section=data-r8&hw=i7&test=json&s=2&l=2

There are test results for different configurations:

JSON responses per second:

  • evhttp-sharp 91,557
  • nancy-libevent2 17,338
  • servicestack-nginx-d 953
  • nancy 896
  • aspnet-jsonnet-mono 863
+2
Nov 11 '14 at 17:17
source share



All Articles