远程调用时代码执行速度是否会变慢? (.net 远程处理)

发布于 2024-12-06 15:29:56 字数 1455 浏览 1 评论 0原文

我的 VB.NET(框架 2)程序中有一个子程序。该子程序不返回任何值,它只是对本地数据库执行各种检查。

程序启动后立即调用sub,大约需要6秒才能完成。

该程序还充当网络远程处理服务器。客户端可以连接到它并调用子程序。

当远程客户端调用 sub 时,大约需要 28 秒才能完成。

这是为什么?在这两种情况下,子程序都是在服务器本地执行的,但是当远程调用时,即使任务完全相同,也会花费更多时间。

使用 .net 远程处理调用时,代码执行速度是否会慢得多?

你知道为什么会发生这种情况吗?

你知道如何解决吗?

感谢您的帮助!

编辑:

对于缺乏信息,我感到非常抱歉。我以为这就足够了。好的,就这样……

这是一个 VB 子程序,它不返回任何值。

网络速度很快,问题是无法到达远程计算机,问题是如果远程调用,代码似乎需要更多时间才能完成。

如果您真的想知道,子的主要部分是一个循环,它将值从 DAO(是的 DAO)记录集复制到集合:

Sub MySub
'This sub can be called both remotemy and locally.

Dim IDsAtTable As New Dictionary(Of Integer, Integer)

‘Open database and fast stuff. 
‘{…}

‘POINT A
RS = DB.OpenRecordset("SELECT ID FROM " & Table & " WHERE IDSucursalFuente=" & IDThisSucursal & " ORDER BY ID")
Fld = RS.Fields("ID")
Do While Not RS.EOF
    ID = Fld.Value
    If Not IDsAtTable.ContainsKey(ID) Then IDsAtTable.Add(ID, ID)
    RS.MoveNext()
Loop
RS.Close()
RS = Nothing
‘POINT B

'Check elements stored at IDsAtTable, this is fast.

‘Close database and fast stuff.
‘{…}    
End Sub

在这两种情况下(远程调用时和在服务器上本地调用时),代码都可以使用相同的数据库(托管在服务器上),处于相同的状态(我的意思是在开始时关闭),具有完全相同的记录。

如果您测量从 A 点到 B 点的时间,如果远程调用子程序,则需要花费更多时间,但正如您所看到的,不涉及网络。对我来说,应该花费相同的时间,但事实并非如此。

我只给sub打了2次电话。一种在本地由服务器进程本身执行,另一种由远程客户端执行。

服务器的处理器负载是相同的。在给定时间只有一个客户端调用子系统。

我不知道 .NET 框架在执行远程调用的代码时是否在幕后执行其他操作,或者为远程调用创建的线程是否慢得多。

I have a sub in my VB.NET (framework 2) program. This sub does not return any value, it just perform various checks on a local DB.

The program calls the sub just after starts, and it takes about 6 seconds to complete.

The program also acts as a net remoting server. Clients can connect to it and call the sub.

When a remote client calls the sub it takes about 28 seconds to complete.

Why is that? In both cases the sub is executed locally in the server, but when called remotely it takes a lot more time, even if the task is exactly the same.

Is somehow the code executed in a much slower thread when called using .net remoting?

Do you know why this happens?

Do you know how to solve it?

Thank you for any help!

EDIT:

I am very sorry for the lack of information. I thought it would be enough. OK here it goes…

This is a VB sub, it does not return any value.

Network is fast, the problem is not to reach the remote computer, the problem is that the code seems to take a lot more to complete if called remotely.

If you really want to know, the main part of the sub is a loop that copies values from a DAO (yes DAO) recordset to a collection:

Sub MySub
'This sub can be called both remotemy and locally.

Dim IDsAtTable As New Dictionary(Of Integer, Integer)

‘Open database and fast stuff. 
‘{…}

‘POINT A
RS = DB.OpenRecordset("SELECT ID FROM " & Table & " WHERE IDSucursalFuente=" & IDThisSucursal & " ORDER BY ID")
Fld = RS.Fields("ID")
Do While Not RS.EOF
    ID = Fld.Value
    If Not IDsAtTable.ContainsKey(ID) Then IDsAtTable.Add(ID, ID)
    RS.MoveNext()
Loop
RS.Close()
RS = Nothing
‘POINT B

'Check elements stored at IDsAtTable, this is fast.

‘Close database and fast stuff.
‘{…}    
End Sub

In both cases (when called remotely and when called locally on the server) the code works with the same DB (hosted on the server), in the same state (I mean closed at the beginning) with the exact same records.

If you measure time from POINT A to POINT B it takes a lot more time if the sub was called remotely, but as you can see, there is no network involved. To me it should take the same amount of time but that’s not the case.

I only call the sub 2 times. One locally by the server process itself, and one by the remote client.

Server's processor load is the same. There is just one client calling the sub at a given time.

I don’t know if .NET framework does other stuff behind the scenes when executes code that was called remotely, or if the thread created for a remote call is much slower.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文