缩放单例
经过几个小时的艰难思考我的基于服务器的应用程序的一些架构问题后,我觉得我将不得不使用单例来实现我的目标。纯粹出于以下原因(证明我的气味是合理的):
- 我不需要将昂贵的对象传递到调用堆栈深处,
- 我可以在任何上下文中对单例管理对象执行函数。 (很多代码已经存在,因此我不愿意重写大量其他工作代码)
除此之外,单例还提出了另一个问题。我的基于服务器的应用程序本质上是一个 DLL,其中包含一个可以调用多个服务器实例的类。服务器实例类包含单例管理对象。通常,这将由 Windows 服务管理,因此服务器:计算机比率将为 1:1。
因此,您可以将其视为(其中 -> 为 1:1,=> 为 1:many):
MACHINE -> ServiceHost(Windows服务?)->服务器实例->单例管理对象
但是,我们希望允许 SaaS 模型,这需要服务主机(无论是 Windows 服务还是 Win32 应用程序)能够根据业务需要启动多个服务器。因此,一台物理机可以运行单个服务器主机,该服务器主机将运行多个服务器实例。
这将是(其中 -> 是 1:1,=> 是 1:many):
MACHINE -> ServiceHost(Windows服务?)=>服务器实例-> 单例管理对象
问题是这些单例将在服务器之间共享。这是不可能发生的。单例必须与服务器实例是 1:1。
假设我无法摆脱这些单例,我是否可以通过调用服务实例类作为单独的进程/内存空间来将这些服务器实例彼此分离?
我只能想象我需要启动多个 EXE(并使用 WCF 进行管理),每个服务器实例一个。这显然不会太好。
After having some difficult hours mulling over some architecture issues for my server-based application, I feel I am going to have to use singletons to accomplish my goal. Purely for the following reasons (justifying my smell):
- I don't need to pass expensive objects deep into a call stack
- I can perform functions on singleton management objects within any context. (A lot of the code already exists and therefore I am unwilling to rewrite extensive chunks of otherwise working code)
Apart from that, Singletons suggest another problem. My server-based application is essentially a DLL with a class that can invoke multiple instances of servers. The server instance class contains the singleton management objects. Ordinarily, this would be managed by a Windows Service, so server:machine ratio will be 1:1.
So you could view it as (where -> is 1:1, => is 1:many):
MACHINE -> ServiceHost (Windows service?) -> Server instance -> Singleton management objects
However, we would like to allow for an SaaS model, which would require a service host (be it a Windows Service or Win32 application) to be able to fire up multiple servers as required by the business. Therefore, a physical machine could run a single server host, which would run multiple server instances.
Which would be (where -> is 1:1, => is 1:many):
MACHINE -> ServiceHost (Windows service?) => Server instance -> Singleton management objects
The problem is that these singletons would be shared across servers. Which cannot happen. The singletons must be 1:1 with the server instance.
Assuming I cannot move away from these singletons, is it possible for me to separate these server instances from each other by invoking the service instance class as a separate process/memory space?
I can only imagine that I would need to fire up multiple EXEs (anduse WCF to manage), one for each server instance. This would obviously not be very good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不同“实例”的不同应用程序域怎么样?
What about different AppDomains for different "Instances"?