我的 Ruby“Time.now”如何才能显示?当我的“ping”发生时,时间是如此之低。时间这么高?

发布于 2024-08-11 20:14:07 字数 393 浏览 9 评论 0原文

我是第一次使用 MongoDB,并尝试对其性能进行计时。我在带有 Windows 7 64 位主机的 VirtualBox Ubuntu 9.10 客户机上运行 ruby​​。 MongoDB 位于远程主机上,而不是在我的局域网上,而是位于互联网云中的某个位置。

这是我的代码:

time1 = Time.now
rows = coll.find(some_criteria)
puts ((Time.now - time1) * 1000).to_s

问题是,时间太短了,我不相信我所看到的。我看到的时间约为 50、100、200 微秒,而我的计算机和远程 mongo 计算机之间的 ping 时间约为 40 毫秒。我对单位有什么误解吗?当 ping 值如此高时,我的时间怎么会这么低?

I'm using MongoDB for the first time and trying to time its performance. I'm running ruby on a VirtualBox Ubuntu 9.10 guest with a Windows 7 64-bit host. MongoDB is on a remote host, not on my lan buit somewhere in the internet cloud.

Here's my code:

time1 = Time.now
rows = coll.find(some_criteria)
puts ((Time.now - time1) * 1000).to_s

The problem is, the time is so small, I don't believe what I'm seeing. I'm seeing times around 50, 100, 200 MICROseconds, while ping times between my computer and the remote mongo computer are around 40 MILLIseconds. Am I misunderstanding the units? How can my timings be so low when the ping is so high?

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

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

发布评论

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

评论(2

我恋#小黄人 2024-08-18 20:14:07

您可以启动数据包嗅探器,启动 irb,然后一次一行发出一些测试命令,但您似乎已经准确地分析了其动态行为。

所以,我想你得到了 coll 和类似 coll = db.collection_names 的东西?我想 coll 必须是一个Enumerable

如果是这样,除了使用 each 方法返回对象之外,该调用中实际上不需要发生任何事情。也许在您向Enumerable请求一些东西之前,实际上什么都不会发生。

您可以尝试:

time1 = Time.now
rows = coll.find(some_criteria)
o = rows.first
puts ((Time.now - time1) * 1000).to_s

这不一定需要更长的时间。调用 db.collection_names 时工作可能已完成。自上而下的 IRB 测试可能会揭示这个问题......

You could start a packet sniffer, start irb, and then issue some test commands one line at a time, but you already seem to have accurately analyzed its dynamic behavior.

So, I suppose you got coll with something like coll = db.collection_names? And I suppose coll must be an Enumerable?

If so, nothing really needs to happen in that call except the return of an object with an each method. Perhaps nothing actually does happen until you ask for something from the Enumerable.

You might try:

time1 = Time.now
rows = coll.find(some_criteria)
o = rows.first
puts ((Time.now - time1) * 1000).to_s

This won't necessarily take any longer. It's possible that the work was done when db.collection_names was called. The irb test, from the top, might shed some light on the issue...

浅暮の光 2024-08-18 20:14:07

简单的答案:这条线没有按照您的预期进行:

rows = coll.find(some_criteria)

具体来说,它没有与服务器通信。

Simple answer: this line isn't doing what you expect:

rows = coll.find(some_criteria)

specifically, it's not communicating with the server.

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