MultiThreaded调用VB COM没有性能提升 [英] No performance improvement for MultiThreaded call to a VB COM

查看:61
本文介绍了MultiThreaded调用VB COM没有性能提升的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将所有源代码包含在附加的MyTest.zip中

http://www.codeguru.com/forum/attach...chmentid=11218


有三个项目:

VBTestCOM项目是一个公寓线程DLL,它有一个函数做一个

存储过程调用。这个DLL将从C ++多线程调用。


C ++测试项目是一个ATL多线程DLL,它只是简单创建了

多线程,并调用VBTestCom''每个线程都有doSPCall函数。


VB客户端:

设置线程号并启动一个循环调用C ++ DLL的Do函数。


你需要在SQL Server NorthWind数据库中创建一个存储过程,比如

这个:

创建PROCEDURE dbo.usp_Test

AS

BEGIN

插入类别(CategoryName,[Description])

values(''CatName'',convert(varchar(30) ,getdate(),9))


WAITFOR延迟''00:00:00.100''

结束

它创建类别中的记录和延迟100毫秒。


在C ++调试中,更改线程编号,您将看不到性能

的改进。跟踪时间如下:

1线程

vb函数调用时间:109

c ++其他代码时间:62


2线程

vb函数调用时间:156

c ++其他代码时间:62


3线程

vb函数调用时间:256

c ++其他代码时间:62


这令人沮丧!帮助!

I have included all the source codes in the attached MyTest.zip
(http://www.codeguru.com/forum/attach...chmentid=11218)

There are three projects:
VBTestCOM project is a apartment threaded DLL, it has one function doing a
stored procedure call. This DLL will be called from C++ multithread.

C++ test project is a ATL multithreaded DLL, it just simple created
multithread, and call VBTestCom''s doSPCall function in each thread.

VB client:
It set thread number and start a loop calling C++ DLL''s Do function.

You need created a stored procedure in SQL Server NorthWind database like
this:
create PROCEDURE dbo.usp_Test
AS
BEGIN
insert Categories(CategoryName,[Description])
values( ''CatName'', convert(varchar(30),getdate(),9))

WAITFOR delay ''00:00:00.100''
end
It create a record in Categories and delay 100 milliseconds.

In C++ debug, Change the thread number and you will see no performance
improvement. Trace time in thread like this:
1 Thread
vb function call time: 109
c++ other code time: 62

2 thread
vb function call time: 156
c++ other code time: 62

3 thread
vb function call time: 256
c++ other code time: 62

It''s frustrating! Help!

推荐答案

嗨wdwedw!
Hi wdwedw!
有三个项目:
VBTestCOM项目是一个公寓线程DLL,它有一个函数做一个
存储过程调用。这个DLL将从C ++多线程调用。

C ++测试项目是一个ATL多线程DLL,它只是简单创建多线程,并在每个线程中调用VBTestCom的doSPCall函数。 />
这令人沮丧!帮助!
There are three projects:
VBTestCOM project is a apartment threaded DLL, it has one function doing a
stored procedure call. This DLL will be called from C++ multithread.

C++ test project is a ATL multithreaded DLL, it just simple created
multithread, and call VBTestCom''s doSPCall function in each thread.

It''s frustrating! Help!




如果VBTestCOM项目是单元线程的(这意味着:

单线程)那么* all *调用此COM -object是序列化的。


所以行为是设计的。

如果你想提高性能,那么切换VBTestCOM

投射到两个或多线程。


-

问候

Jochen


我关于Win32和.NET的博客
http://blog.kalmbachnet。 de /




" Jochen Kalmbach [MVP]" <无******************** @ holzma.de>在消息中写道

新闻:OU ************* @ TK2MSFTNGP09.phx.gbl ...

"Jochen Kalmbach [MVP]" <no********************@holzma.de> wrote in message
news:OU*************@TK2MSFTNGP09.phx.gbl...
嗨wdwedw!
Hi wdwedw!
有三个项目:
VBTestCOM项目是一个公寓线程DLL,它有一个函数做一个存储过程调用。这个DLL将从C ++多线程调用。

C ++测试项目是一个ATL多线程DLL,它只是简单创建多线程,并在每个线程中调用VBTestCom的doSPCall函数。 />
这令人沮丧!帮助!
如果VBTestCOM项目是单元线程的(这意味着:
单线程)那么*所有*调用这个COM对象的序列化。

所以行为是设计的。
如果你想提高性能,那么将VBTestCOM项目切换到两个或多线程。
There are three projects:
VBTestCOM project is a apartment threaded DLL, it has one function doing
a stored procedure call. This DLL will be called from C++ multithread.

C++ test project is a ATL multithreaded DLL, it just simple created
multithread, and call VBTestCom''s doSPCall function in each thread.

It''s frustrating! Help!
If the VBTestCOM project is apartment-threaded (that means:
single-threaded) then *all* calls to this COM-object is serialized.

So the behaviour is by design.
If you want to improve the performance, then switch the VBTestCOM project
to both or multi-threaded.




哪个是不可能使用VB,VB6只能生成单线程

公寓(STA)或单一(在主公寓上实例化)COM

DLL'' 。


威利。 -
问候
Jochen

关于Win32和.NET的博客
http://blog.kalmbachnet.de/



这很正常,你的VB对象是一个STA对象,你初始化

线程进入MTA。结果是,每个调用都要在MTA和对象所在的STA之间进行封送,这会使你的b / b
性能下降。为STA初始化你的公寓,然后再试一次。


Willy。

" wdwedw" < WD **** @ discussions.microsoft.com>在留言中写道

news:98 ********************************** @ microsof t.com ...
This is quite normal, your VB object is a STA object, and you initialize the
thread to enter the MTA. The result is that each call as to be marshaled
between the MTA and the STA where the object lives, this kill your
performance. Initialize your apartment for STA and try again.

Willy.
"wdwedw" <wd****@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
我已在所附的MyTest.zip中包含所有源代码
http://www.codeguru.com/forum/attach...chmentid=11218

有三个项目:
VBTestCOM项目是一个公寓线程DLL,它有一个函数做一个
存储过程调用。这个DLL将从C ++多线程调用。

C ++测试项目是一个ATL多线程DLL,它只是简单创建多线程,并在每个线程中调用VBTestCom的doSPCall函数。 VB客户端:
设置线程号并启动一个循环调用C ++ DLL的Do函数。

你需要在SQL Server NorthWind数据库中创建一个存储过程
这个:
创建程序dbo.usp_Test
AS
BEGIN
插入类别(CategoryName,[Description])
值(''CatName'',转换(varchar(30),getdate(),9))

WAITFOR延迟''00:00:00.100''
结束
它在类别和延迟中创建记录100毫秒。

在C ++调试中,更改线程编号,您将看不到性能改进。跟踪时间在线程中如下:
1线程
vb函数调用时间:109
c ++其他代码时间:62

2线程
vb函数调用时间:156
c ++其他代码时间:62
3线程
vb函数调用时间:256
c ++其他代码时间:62
令人沮丧!帮助!
I have included all the source codes in the attached MyTest.zip
(http://www.codeguru.com/forum/attach...chmentid=11218)

There are three projects:
VBTestCOM project is a apartment threaded DLL, it has one function doing a
stored procedure call. This DLL will be called from C++ multithread.

C++ test project is a ATL multithreaded DLL, it just simple created
multithread, and call VBTestCom''s doSPCall function in each thread.

VB client:
It set thread number and start a loop calling C++ DLL''s Do function.

You need created a stored procedure in SQL Server NorthWind database like
this:
create PROCEDURE dbo.usp_Test
AS
BEGIN
insert Categories(CategoryName,[Description])
values( ''CatName'', convert(varchar(30),getdate(),9))

WAITFOR delay ''00:00:00.100''
end
It create a record in Categories and delay 100 milliseconds.

In C++ debug, Change the thread number and you will see no performance
improvement. Trace time in thread like this:
1 Thread
vb function call time: 109
c++ other code time: 62

2 thread
vb function call time: 156
c++ other code time: 62

3 thread
vb function call time: 256
c++ other code time: 62

It''s frustrating! Help!



这篇关于MultiThreaded调用VB COM没有性能提升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆