如何获取正在运行的 ruby 进程的数据?
我有一个带有缓存和数据库的数据存储,很简单。棘手的部分是我想要一种方法来控制数据存储是否实时访问数据库。也就是说,当进程运行时,我希望能够切换它是否连接到数据库。
我查看了环境变量,但这些变量似乎没有随着进程的运行而更新。有没有一种简单的方法可以从命令行获取一些信息到正在运行的进程中,或者我只需要依赖操作员在发生灾难时能够删除数据库侦听器?
请注意,这一切都是在 vanilla ruby 中完成的,而不是在 Rails 上的 ruby。
谢谢! -杰西
I have a datastore with a cache and a db, simple. The tricksy part is that I want a way to control if the the datastore hits the db in a real-time way. That is to say while the process is running I want to be able to toggle if it's connected to the db or not.
I looked into env variables, but it doesn't seem like those get updated as the process runs. Is there a simple way to get a bit from the command line into the running process, or do I just need to rely on ops being able to drop the db listeners in case of disaster?
Note that this is all being done in vanilla ruby - not ruby on rails.
Thanks!
-Jess
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您可以使用命名管道进行简单通信:
并且您可以通过写入命名管道来控制外部数据库访问:
这会导致:
I think you can use named pipes for simple communication:
And you can control your db access externally by writing to the named pipe:
Which results in:
共享内存策略可能值得考虑。假设您在 POSIX 系统上运行,请查看 mmap 来获取内存映射文件,以及 SysVIPC 用于消息队列、信号量和共享内存。
A shared-memory strategy might be worth considering. Assuming you're running on a POSIX system, check out mmap for memory-mapped files, and SysVIPC for message queues, semaphores, and shared memory.
假设 *NIX,你考虑过信号吗? (
kill -HUP pid
) - http://ruby- doc.org/core/classes/Signal.htmlAssuming *NIX, have you considered signals? (
kill -HUP pid
) - http://ruby-doc.org/core/classes/Signal.html