寻找资源管理/分配系统

发布于 2024-08-17 06:49:03 字数 362 浏览 8 评论 0原文

我需要的是一个可以定义简单对象的系统(例如,一个可以有“操作系统”和“版本”字段以及其他元数据(IP、MAC 地址等)的“服务器”)。
我希望能够以安全的方式从系统请求对象,例如,如果我定义一个“服务器”,可以由 3 个客户端同时使用,那么如果 4 个客户端同时请求一个服务器时间,必须等到服务器被释放。
此外,我需要能够以某种查询方式执行请求,例如 allocate(type=System, os='Linux', version=2.6)

语言不太重要,但Python是一个优势。

过去几天我一直在谷歌上搜索类似的东西,但一无所获,也许这种系统有一个我不知道的更好的名字。

有什么建议吗?

谢谢!

What I need is a system I can define simple objects on (say, a "Server" than can have an "Operating System" and "Version" fields, alongside other metadata (IP, MAC address, etc)).
I'd like to be able to request objects from the system in a safe way, such that if I define a "Server", for example, can be used by 3 clients concurrently, then if 4 clients ask for a Server at the same time, one will have to wait until the server is freed.
Furthermore, I need to be able to perform requests in some sort of query-style, for example allocate(type=System, os='Linux', version=2.6).

Language doesn't matter too much, but Python is an advantage.

I've been googling for something like this for the past few days and came up with nothing, maybe there's a better name for this kind of system that I'm not aware of.

Any recommendations?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最后的乘客 2024-08-24 06:49:03

并发应用程序中的资源限制(例如“最多 3 个客户端”示例)通常是通过使用信号量(或更准确地说,计数信号量)来实现的。

您通常使用一些“计数”来初始化信号量(即对该资源的并发访问的最大数量),并且每次客户端开始使用该资源时都会递减该计数器,并在客户端完成使用该资源时递增该计数器。信号量的实现保证了“递增”和“递减”操作是原子的。

您可以在 Wikipedia 上阅读有关信号量的更多信息。我对 Python 不太熟悉,但我认为这两个链接可以提供帮助:

Resource limitation in concurrent applications - like your "up to 3 clients" example - is typically implemented by using semaphores (or more precisely, counting semaphores).

You usually initialize a semaphore with some "count" - that's the maximum number of concurrent accesses to that resource - and you decrement this counter every time a client starts using that resource and increment it when a client finishes using it. The implementation of semaphores guarantees the "increment" and "decrement" operations will be atomic.

You can read more about semaphores on Wikipedia. I'm not too familiar with Python but I think these two links can help:

拥抱影子 2024-08-24 06:49:03

对于 Java,有一个非常好的标准库具有此功能:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html

只需创建一个带有 Semaphore 字段的类:

 class Server {
   private static final MAX_AVAILABLE = 100;
   private final Semaphore available = new Semaphore(MAX_AVAILABLE, true);
   // ... put all other fields (OS, version) here...
   private Server () {}

   // add a factory method
   public static Server getServer() throws InterruptedException {
     available.acquire();
     //... do the rest here
   }

 }

编辑:

如果您希望事情更加“可配置”,请考虑使用 AOP 技术,即创建基于信号量的同步方面。

编辑:

如果您想要完全独立的系统,我想您可以尝试使用任何支持行级锁定作为信号量的现代数据库(例如PostgreSQL)系统。例如,为每行创建 3 行代表一个服务器,如果空闲则锁定它们(例如“select * from server where is_used = 'N' for update”),将所选服务器标记为已使用,最后取消标记,提交事务。

For Java there is a very good standard library that has this functionality:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html

Just create a class with Semaphore field:

 class Server {
   private static final MAX_AVAILABLE = 100;
   private final Semaphore available = new Semaphore(MAX_AVAILABLE, true);
   // ... put all other fields (OS, version) here...
   private Server () {}

   // add a factory method
   public static Server getServer() throws InterruptedException {
     available.acquire();
     //... do the rest here
   }

 }

Edit:

If you want things to be more "configurable" look into using AOP techniques i.e. create semaphore-based synchronization aspect.

Edit:

If you want completely standalone system, I guess you can try to use any modern DB (e.g. PostgreSQL) system that support row-level locking as semaphore. For example, create 3 rows for each representing a server and select them with locking if they are free (e.g. "select * from server where is_used = 'N' for update"), mark selected server as used, unmark it in the end, commit transaction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文