因域名解析导致数据库连接延迟分析

一、现状记录

[[email protected] ~]$ /sbin/ifconfig

eth1      Link encap:Ethernet  HWaddr 00:25:90:04:AB:6B 

          inet addr:192.168.9.140  Bcast:192.168.15.255  Mask:255.255.248.0

          inet6 addr: fe80::225:90ff:fe04:ab6b/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:23530402 errors:0 dropped:0 overruns:0 frame:0

          TX packets:10959123 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:15308483748 (14.2 GiB)  TX bytes:10087987532 (9.3 GiB)

--IP地址为192.168.9.140

[[email protected] ~]$ more /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1               ecp-db localhost.localdomain localhost

192.168.9.140   node1.srtcloud.com

--域名node1.srtcloud.com对应ip192.168.9.140

[[email protected] ~]$ lsnrctl status

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=node1.srtcloud.com)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 10.2.0.5.0 - Production

Start Date                04-NOV-2011 09:08:51

Uptime                    21 days 4 hr. 58 min. 45 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /opt/oracle/product/10.2.0/db_1/network/admin/listener.ora

Listener Log File         /opt/oracle/product/10.2.0/db_1/network/log/listener.log

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=node1.srtcloud.com)(PORT=1521)))

Services Summary...

Service "ecp" has 2 instance(s).

  Instance "ecp", status UNKNOWN, has 1 handler(s) for this service...

  Instance "ecp", status READY, has 1 handler(s) for this service...

Service "ecpXDB" has 1 instance(s).

  Instance "ecp", status READY, has 1 handler(s) for this service...

Service "ecp_XPT" has 1 instance(s).

  Instance "ecp", status READY, has 1 handler(s) for this service...

Service "ora11g" has 2 instance(s).

  Instance "ora11g", status UNKNOWN, has 1 handler(s) for this service...

  Instance "ora11g", status READY, has 1 handler(s) for this service...

Service "ora11gXDB" has 1 instance(s).

  Instance "ora11g", status READY, has 1 handler(s) for this service...

The command completed successfully

--说明:ora11g是oracle 11g,ecp是oracle 10g

--当前使用域名node1.srtcloud.com监听

[[email protected] ~]$ more /opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora

# tnsnames.ora Network Configuration File: /opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

ECP =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = node1.srtcloud.com)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ecp)

    )

  )

ORA11G =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = node1.srtcloud.com)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ora11g)

    )

  )

--tns也通过域名访问

[[email protected] ~]$ more /etc/resolv.conf

nameserver 211.155.235.201

nameserver 211.155.235.188

--当前有效的dns服务器

[[email protected] ~]$ more /etc/nsswitch.conf |grep hosts:

hosts:     files dns

--域名解析顺序

二、数据库正常工作分析
1、tns工作:客户端通过tns访问数据库,tns配置的是域名访问,所以需要解析,因为此刻解析的顺序是先利用/etc/hosts解析,所以读取hosts文件,获取到ip,然后访问对应数据库,和监听接触。
2、监听工作:监听的是域名,其实也是通过hosts解析成ip的
3、这里能够正常的工作,是因为hosts文件解析了域名

三、模拟数据库访问延迟

[[email protected] ~]$ more /etc/nsswitch.conf |grep hosts:

hosts:     dns files

--先使用dns服务器解析,再使用hosts文件

[[email protected] ~]$ more /etc/resolv.conf

nameserver 11.1.1.1

--无效的dns服务器

[[email protected] ~]$ sqlplus chf/xifenfei@ora11g

SQL*Plus: Release 10.2.0.5.0 - Production on Fri Nov 25 14:44:55 2011

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

--会在这里一个很长的时间等待

[[email protected] ~]$ lsnrctl status

LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 25-NOV-2011 14:48:26

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=node1.srtcloud.com)(PORT=1521)))

--也会一个长时间的等待

--问题原因:就是因为解析域名的时候,先去访问dns服务器,因为该ip非dns服务器ip,所以会一直等待该ip超时,

--然后访问hosts文件获取ip地址(这个就是为什么我们登录或者查看监听状态的时候,会出现如此长的时间的等待)

其实因为dns延迟的现象有很多种,我这里只是举了一个最简单,比较常见的例子,在处理因dns解析的监听延迟的问题上,可以参考下面几点:
1、如果非特殊情况,尽可能使用ip地址在监听和tns中
2、如果是使用域名,请尽可能使用hosts解析,解析顺序配置为files优先(因为dns服务器有很多不确定,不可控因素)
3、如果一定要使用dns服务器解析,请把稳定的dns服务器配置在第一项,尽可能避免出现dns服务器不可达或者不存在该域名的现象

转:http://www.xifenfei.com/2011/11/%e5%9b%a0%e5%9f%9f%e5%90%8d%e8%a7%a3%e6%9e%90%e5%af%bc%e8%87%b4%e6%95%b0%e6%8d%ae%e5%ba%93%e8%bf%9e%e6%8e%a5%e5%bb%b6%e8%bf%9f%e5%88%86%e6%9e%90.html

时间: 2024-08-09 10:44:37

因域名解析导致数据库连接延迟分析的相关文章

网络延迟分析

网络延迟分析 网络延迟分析框架(TCP) PS: UDP的设计目标是快速但不可靠,所以它没有内置任何延迟检测并从中恢复的功能.相反,它依赖于应用层协议(和ICMP)来解决数据可靠传输的问题.

$.hover()事件 快速触发导致动作延迟问题的解决

$.hover()事件 快速触发导致动作延迟问题的解决,在触发hover 事件中我们给相应的 事件前加上stop()即可. 如 $(".a").hover(function(){ $(this).find(".top").stop().toggle();  $(this).find(".hidden").stop().slideToggle();  });

【转】STM32擦除内部FLASH时间过长导致IWDG复位分析

@20119-01-29 [小记] STM32擦除内部FLASH时间过长导致IWDG复位分析 原文地址:https://www.cnblogs.com/skullboyer/p/10335371.html

Android 低内存导致monkey killed分析指南

现象描述: monkey --pkg-blacklist-file storage/sdcard0/blacklist.txt  --ignore-security-exc eptions --monitor-native-crashes -s 800 -v -v -v  --throttle 1427 180000 >sdcard /Monkey.log shes -s 800 -v -v -v  --throttle 1427 180000 >sdcard/Monkey.log      

数据库连接池分析

参考文献 1.一个效果非常不错的JAVA数据库连接池 2.使用 JAVA 中的动态代理实现数据库连接池 3.MySql与oracle的JDBC测试程序 分析 参考文献1是一个用java实现的数据库连接池,可以参考其代码实现,最好也看看java源代码是怎么实现数据库连接池的,两者进行比较. 参考文献2中提到了动态代理,之前写过的一片博客:设计模式之代理模式之二(Proxy)中也讲到了动态代理,这里可以参考一下. 下面首先给出参考1中的代码示例,具体见ConnectionPool.java,修改了部

在docker以FPM-PHP运行php,慢日志导致的BUG分析

问题描述: 最近将IOS书城容器化,切换流量后.正常的业务测试了一般,都没发现问题.线上的错误监控系统也没有报警,以为迁移工作又告一段落了,暗暗的松了一口气.紧接着,报警邮件来了,查看发现是一个苹果支付相关接口调用的curl错误,错误码为"56",错误描述为:“Failure with receiving network data”接收网络数据失败. 机器 : 192.168.1.1当前URL : /xxx/recharge/apple?xxxxxxxxxxxxx接口URL : htt

Thinkphp分布式数据库连接代码分析

Thinkphp作为国内的一款流行框架,相信使用的人一定不在少数.本篇我们来分析一下Thinkphp中比较重要的一部分——分布式数据库的连接. 当然了,我们在这里不是去将如何使用模型去对数据库进行增删改查.我们是对其底层的连接代码做一个分析,可以帮助大家更好的理解thinkphp对数据库的操作.方便我们以后的使用. 一.单一数据库的连接 在使用的时候,单一数据库的连接配置非常简单.我们只需要在配置文件中配置一下的信息即可. 'DB_TYPE' => 'mysql','DB_HOST' => '

Redis源码分析(三十一)--- latency延迟分析处理

每当提到延时统计的时候,一定想到的一个名词就是"性能测试",没错,在Redis的redis_benchmark文件中,的确用到了延迟文件中的相关信息.在Redis中的官方解释此文件: /* The latency monitor allows to easily observe the sources of latency * in a Redis instance using the LATENCY command. Different latency * sources are m

Handler导致内存泄露分析

Handler mHandler = new Handler() {    @Override    public void handleMessage(Message msg) {            // do something.    }}```当我们这样创建`Handler`的时候`Android Lint`会提示我们这样一个`warning: In Android, Handler classes should be static or leaks might occur.`. 一