我的 Ruby“Time.now”如何才能显示?当我的“ping”发生时,时间是如此之低。时间这么高?
我是第一次使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以启动数据包嗅探器,启动 irb,然后一次一行发出一些测试命令,但您似乎已经准确地分析了其动态行为。
所以,我想你得到了
coll
和类似coll = db.collection_names
的东西?我想coll
必须是一个Enumerable?如果是这样,除了使用
each
方法返回对象之外,该调用中实际上不需要发生任何事情。也许在您向Enumerable请求一些东西之前,实际上什么都不会发生。您可以尝试:
这不一定需要更长的时间。调用 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 likecoll = db.collection_names
? And I supposecoll
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:
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...简单的答案:这条线没有按照您的预期进行:
具体来说,它没有与服务器通信。
Simple answer: this line isn't doing what you expect:
specifically, it's not communicating with the server.