C#(单声道)与跨线程一致的静态变量主机的Linux Web服务器 [英] C# (mono) Linux web server hosting with consistent static variables across threads

查看:184
本文介绍了C#(单声道)与跨线程一致的静态变量主机的Linux Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道的C#(单声道)的Linux Web服务器主机配置,支持跨线程一致的静态变量(即不是每个线程实例的CGI模式)?

Does anybody know of a C# (mono) Linux web server hosting configuration that enables consistent static variables across threads (ie not the CGI model of an instance per thread)?

详细信息

我有一些C#(单声道)code,我们需要在Linux主机作为一个简单的Web应用程序的一部分。我们不需要任何传统的ASP甚至asp.net mvc的功能,真的我们只需要到特定的URL与基于共享的静态变量的动态内容的反应能力。

I have some c# (mono) code that we need to host on linux as part of a simple web app. We don't need any traditional asp or even asp.net mvc features, really we just need the ability to respond to specific urls with dynamic content based on shared static variables.

静态变量:
我们确实有一个特殊的要求,我们需要静态变量保留其所有传入的请求值(它们在Windows上做到与ASP.net MVC应用程序相同的方式)。托管的单C#的Web应用程序,如Apache的常用方法是mod_mono出现每个线程的C#应用​​程序实例模式使用那里将是我们每一个都有自己的静态变量的C#应用​​程序的多个独立实例。这是我们需要避免的问题。我需要托管C#应用程序,它提供了一套共享的静态变量,所有传入的请求会看到一个共同的应用程序的方式。这是确定的,如果当应用程序回收的静态变量被重置(就像在正常的IIS / MVC),只要再循环并不多见。

Static Variables: The one special requirement we do have is that we need static variables to retain their value across all incoming requests (the same way they do on windows with an ASP.net mvc application). Common ways of hosting a mono c# web app like Apache mod_mono appear to use an 'c# application instance per thread' model where there would be multiple independent instances of our c# application each with their own static variables. That is the problem we need to avoid. I need a way of hosting a c# application that provides one common app with a shared set of static variables that all incoming requests will see. It is ok if when the app recycles that the static variables get reset (just like in normal IIS/MVC), so long as recycles are infrequent.

背景是,这个Web应用程序需要持有大量的RAM中的数据在一个静态变量,并迅速回答有关数据的问题。具有开放式应用程序为每个线程将限制RAM资源的副本太多的数据重新加载到内存中频繁会使应用程序太慢(偶尔的回收将如IIS / Asp.net MVC有没有关系)。该系统工作得非常好在Windows / IIS7(每秒50,000动态请求),我们的不要想改变这种结构,所以我在寻找的答案涉及到托管不改变应用程序设计。

The background is that this web app needs to hold a large amount of data in RAM in a static variable and rapidly answer questions about that data. Having a copy of the app open for each thread would limit RAM resources too much and reloading the data into memory frequently would make the app too slow (occasional recycles like IIS/Asp.net MVC has are fine). The system works amazingly well on Windows/IIS7 (50,000+ dynamic requests per second) and we do not want change this architecture, so the answer I'm looking for relates to hosting not changing the application design.

推荐答案

是mod_mono不会产生一个新的单过程为每个新的Web请求。如果你使用FastCGI的服务器Apache或nginx的沿着它也没有。

mod_mono does not spawn a new mono process for each new web request. Neither does it if you use the fastcgi server along with apache or nginx.

编辑:静态变量是相同的应用程序域内的共享。这(如果你使用的是mod_mono,XSP或单FastCGI的服务器,不管)的Microsoft .NET IIS和单也是如此。即便如此Apache生成多个工作线程和一个请求由一个工作线程来处理,只有在任何特定时间运行一个单声道的过程(除非您配置了多个asp.net应用程序,再有就是每个应用程序一个)

Static variables are shared within the same Application Domain. This holds true for Microsoft .NET IIS and for mono (no matter if you are using mod_mono, xsp or mono-fastcgi-server). Even so apache spawns multiple worker threads and a single request is handled by a single worker thread, there is only a single mono process running at any given time (except if you have configured multiple asp.net applications, then there is one per application).

单尝试,以实现ASP.NET 100%的兼容性为好,所以是由设计没有什么不同的行为!

Mono tries to achieve 100% compatibility for ASP.NET as well, so there is no different behaviour by design!

你的程序在Linux上的不同的行为是最有​​可能不相关的是mod_mono处理请求的方式,而是在单本身,还是你的code(通过一个平台的假设,即不抱在Linux上真正的错误)。你真的应该使用调试已MonoDevelop的/ XSP并试图更清晰地找出问题,或贴上一些样本code。

The different behaviour of your program on linux is most likely not related to how mod_mono handles requests, but rather a bug in mono itself, or your code (i.e. by making a platform assumption that does not hold true on linux). You should really debug using MonoDevelop/xsp and try to pinpoint the problem more clearly, or paste some sample code here.

这篇关于C#(单声道)与跨线程一致的静态变量主机的Linux Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆