.NET Oracle托管数据访问连接池无法正常工作或运行缓慢 [英] .NET Oracle managed data access connection pooling not working or slow

查看:230
本文介绍了.NET Oracle托管数据访问连接池无法正常工作或运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近注意到,当我们的应用程序对Oracle数据库执行SQL查询时,它总是至少需要200毫秒才能执行.查询的简单程度与复杂程度无关紧要,最短时间约为200毫秒.我们正在使用适用于Oracle 11g的Oracle托管数据访问驱动程序.

I recently noticed that when our application does an SQL query to the Oracle database, it always takes at least 200 ms to execute. It doesn't matter how simple or complex the query is, the minimum time is about 200 ms. We're using the Oracle Managed Data Access driver for Oracle 11g.

然后,我创建了一个简单的控制台应用程序来测试连接.我注意到,如果像下面的示例那样创建连接,那么每个cmd.ExecuteReader方法都要花费额外的200毫秒(打开连接)吗?

I then created a simple console application to test the connection. I noticed that if I create the connection like in the example below, then every cmd.ExecuteReader method takes the extra 200 ms (opening the connection)?

        using (OracleConnection con = new OracleConnection(connStr))
        {
            con.Open();
            OracleCommand cmd = con.CreateCommand();
            ...
        }

在创建这样的连接时,连接状态始终为Closed(如果连接被池化了,连接状态是否会打开?).

The connection state is always Closed when creating the connection like this (shouldn't it be open if the connections are pooled?).

如果我在程序开始时打开连接,然后将打开的连接传递给方法,则cmd.ExecuteReader大约需要0-5毫秒才能返回.我尝试将Pooling=true添加到连接字符串中,但它似乎没有任何作用(无论如何,它应该是默认值).

If I open the connection at the start of the program and then pass the opened connection to the method, the cmd.ExecuteReader takes about 0-5 ms to return. I've tried to add Pooling=true to the connection string but it doesn't seem to do anything (it should be the default anyway).

这是否意味着连接池无法正常工作?还是有其他原因导致cmd.ExecuteReader花费额外的200毫秒执行时间?

Does this mean that the connection pooling is not working as it should? Or could there be any other reason why the cmd.ExecuteReader takes the extra 200 ms to execute?

问题与本期几乎相同,除了我们使用的是Oracle

The problem is almost the same as in this issue, except that we're using Oracle Connection pooling is slower than keeping one connection open

推荐答案

经过大量测试和研究,我终于弄清了额外的200毫秒来自哪里:我的虚拟计算机的网络适配器.我正在使用VMWare Player,并且连接已配置为"NAT"模式. 当我将连接更改为桥接"模式时,延迟被删除了.

After a lot of testing and research I finally figured out where the extra 200ms comes from: my virtual computer's network adapter. I'm using VMWare Player and the connection was configured to "NAT" mode. When I changed the connection to "Bridged" mode the latency was removed.

这篇关于.NET Oracle托管数据访问连接池无法正常工作或运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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