友善交流技术...

发布新日志

  • time_wait 过多解决办法

    2013-12-16 11:09:31

     这几天做性能测试通过监控发现大量的time_wait状态的链接
    监控现象:
          1 FIN_WAIT2
         80 ESTABLISHED
      50486 TIME_WAIT 
    造成的结果
      web无再可以使用的链接,去链接DB,造成大量的请求失败.

    解决办法:

     net.ipv4.tcp_max_tw_buckets = 5000 #本参数可以控制TIME_WAIT数量
     net.ipv4.tcp_tw_reuse = 1
     net.ipv4.tcp_tw_recycle = 1
     net.ipv4.tcp_fin_timeout = 5

    遗留问题
     
     net.ipv4.tcp_max_tw_buckets = 5000 如果设置太小会造成报错的.
    Dec 13 17:01:52 web-adc-31-69 kernel: TCP: time wait bucket table overflow
    Dec 13 17:01:52 web-adc-31-69 kernel: TCP: time wait bucket table overflow
    Dec 13 17:01:57 web-adc-31-69 kernel: __ratelimit: 5243 callbacks suppressed
     目前还不知道有什么办法可以解决本问题的.

  • python pywinauto

    2013-09-23 16:10:43

    Pywinauto 自动化测试

    这几天没有事做,想做自动化测试,看看了pywinauto 感觉也还好。支持标准的win组件!非标准的,好像不支持!

    安装部属

    安装pywinauto

    Run python.exe setup.py install 

    安装依赖包

    To check you have it installed correctly Run Python

    实现NOTEPAD自动化写及保存

    from pywinauto import Application

    import time

    app = Application.start("notepad")

    app.__setattr__("name","notepad")

    time.sleep(2)

    app.Notepad.edit.TypeKeys('Test ......................')

    app.Notepad.edit.TypeKeys('Test ......................')

    time.sleep(2)

    #中文版本操作

    app.Notepad.MenuSelect(u"文件(F)->另存为(A)...")

    app.Dialog.edit.TypeKeys(u'TestFile.txt')

    time.sleep(2)

    #点击保存

    app.Dialog.Button1.Click()

    time.sleep(2)

    #文件存在的话,要覆盖,所以再一次点击是

    app.Dialog.Button1.Click()

    time.sleep(1)

    #退出notepad

    app.Notepad.Close()

    在网上搜索了很久,也没有很专业的讲解pywinauto的使用。唉!!!自己只能摸着石头过河了!!!

  • python read xml

    2012-12-12 13:56:45

    from xml.etree.ElementTree import ElementTree
    from xml.etree.ElementTree import Element
    from xml.etree.ElementTree import SubElement
    from xml.etree.ElementTree import dump
    from xml.etree.ElementTree import Comment
    from xml.etree.ElementTree import tostring
    from xml.etree.ElementTree import fromstring
    from xml.etree import ElementTree

    data='''<?xml version="1.0" encoding="utf-8"?>
    <PurchaseOrder>
       <item ty="tester" qtp="V9.0">
        <name>item1-name</name>
        <name>item1-name</name>
        <description>item1 Smash</description>
      </item>
       <item1>
        <name>item2-name</name>
        <description>item2 Smash</description>
      </item1>
       <dbconf>
        <name>root</name>
        <passwd>
    <passwd1>111111</passwd1>
    <passwd2>222222</passwd2>
    </passwd>
    <IP>1.1.1.1</IP>
      </dbconf>
    </PurchaseOrder>'''

    #读文件和读xml数据两种方式
    #root=ElementTree(file='d:\\book.xml').getroot()
    root = ElementTree.fromstring(data)

    #获取二级目录下的数据
    print root.find('item/name').text
    print root.find('item1/name').text

    #获取item属性值
    print root.find('item').attrib['ty']
    print root.find('item').attrib['qtp']

    #获取多级目录下的数据
    print root.find('dbconf/name').text
    print root.find('dbconf/passwd/passwd1').text
    print root.find('dbconf/passwd/passwd2').text
    print root.find('dbconf/IP').text




  • Python 扩展模块下载地址

    2012-11-21 17:39:26

    Python 扩展模块下载地址:

    http://www.lfd.uci.edu/~gohlke/pythonlibs/#pymedia 
  • python 冒泡算法

    2012-10-30 15:34:30

    #冒泡算法
    import os,sys
    list=[0,3,4,2,9,8,5]
    for i in range(len(list)):
        j=i+1
        for j in range(len(list)-1):
            if list[i]<list[j]:
               a=list[j]
               list[j]=list[i]
               list[i]=a

    print list


               




  • Python Post 请求

    2012-04-27 10:29:15

    POST第一种方法:

    请求的数据格式为:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <BossCustomerVO>
        <userId>test</userId>
        <applicationId>SME-MEETING</applicationId>
        < billingMode >006317</billingMode >
        <email>user@163.com</email>
        <patTitle>etester</patTitle>
        < description>memo</ description >
        </BossCustomerVO>

    去掉<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 就可以直接在使用python post 发送数据

    import urllib2
    cookies = urllib2.HTTPCookieProcessor()
    opener = urllib2.build_opener(cookies)
    xml_request = '''<bossCustomerVO><userId>99tdfdf</userId><applicationId>SME-MEETING</applicationId>\
    <email>email_yrdydfasdfsadfsad@163.com</email><payTitle>鍒涙兂绌洪棿</payTitle>\
    <description>memo</description></bossCustomerVO>'''

    request = urllib2.Request(
            url     = 'http://192.168.1.1:1111/stomer',
            headers = {'Content-Type' : 'application/xml','charset':'UTF-8'},
            data    = xml_request)

    f=opener.open(request)
    print f.read()

     

    POST另外一种实现方式

    #POST request other methods

    import urllib2, urllib

    data = {'name' : 'www', 'password' : '123456'}
    f = urllib2.urlopen(
            url     = 'http://www.ideawu.net/',
            data    = urllib.urlencode(data)
      )
    print f.read()

  • Python 获取当前时间

    2012-04-17 12:10:06

    Python 获取当前时间

    1、获取当前时间:具体的代码实现

    import time
    ntime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    print ntime

    2012-04-17 12:08:31  

     

    2、时间转换成毫米

      时间格式为: 10:45:34:750 转换成毫米。具体的代码实现

        def timeopf(self,ftime):
            import time ,datetime,string
            tt=ftime.split(":")
            sum=((int(tt[0])*3600+int(tt[1])*60+int(tt[2]))*1000 + int(tt[3]))
            return sum

     

     

  • python list操作

    2012-04-13 13:05:51

    python list操作

    list操作:快速创建list、新增item、删除item、重新赋值item、颠倒item顺序、检索item

    快捷创建list,两种方式:split方法、list函数和range函数配合使用。
     

    split方法。写一个字符串,字符之间以空格分隔,然后对该字符串使用split方法。
    a_list = 'a b c d e f g'.spit() //创建列表['a','b','c','d','e','f','g'],但这种写法要简洁很多

    list函数和range函数配合使用。可以快速地创建一个非常大的列表。
    a_list = list(range(100))  //很方便地创建一个0到99的列表

    新增item,四种方式:concatenation、append、extend、insert,后三种方式都是列表的方法。
    示例列表a_list = ['a']:
    concatenation添加。它添加的是另外一个列表,两个列表组合成一个新的列表:
    a_list = a_list + [2.0,3]  //列表较长时,可能会消耗大量内存

    append方法添加。它在原列表末尾添加一个item,item类型可以是任意的:
    a_list.append('hello') //在原有列表末尾添加一个类型为字符串的item
    a_list.append(['hello'])  //在原有列表末尾添加一个类型为列表的item

    extend方法添加。它类似于concatenation,只接受列表参数,并把列表中的item分解,然后添加到原有的列表:
    a_list.extend('hello') //在原有列表末尾添加5个字符item,因为它把hello视为列表
    a_list.extend(['hello'])  //在原有列表末尾添加1个item

    insert方法添加。在原有列表中插入item:
    a_list.insert(0,'c')  //在原有列表的0位置添加一个字符
    a_list.insert(0.['c'])  //在原有列表的0位置添加一个列表


    删除item,三种方式:del、remove、pop,后两种方式都是列表的方法。
    示例列表:a_list = ['a','b','c','hello']:
    del删除。它按item的索引值或切片进行删除:
    del a_list[0]   //删除列表的第一个值
    del a_list[:2]  //删除列表的前两个值。(为什么不是前三个呢?因为python的列表切片,包含前一个索引,但不包括后一个索引)

    remove方法删除。它不按item索引,而是按照item的值进行删除:
    a_list.remove('a')  //把a从列表中删除

    pop方法删除。它按item索引值进行删除,同时返回被删除的item值;若不指定索引,默认删除最后一个item:
    a_list.pop(1)  //删除列表的第二个值,并返回被删除的值
    a_list.pop()  //删除列表的最后一个值,并返回被删除的值


    重新赋值item,对指定索引使用assignment符号进行赋值:
    示例列表:a_list = ['a','b','c','hello']:
    a_list[1] = 'bbb' //列表的第二个值b,将被替换为bbb


    颠倒列表的item顺序,reverse方法:
    示例列表:a_list = ['a','b','c','hello']:
    a_list.reverse() //列表的item顺序将被从后到前重新排列,更改为['hello','c','b','a']


    检索列表的值,四种方式:in、not in、count、index,后两种方式是列表的方法。
    示例列表:a_list = ['a','b','c','hello']:
    判断值是否在列表中,in操作符:
    'a' in a_list  //判断值a是否在列表中,并返回True或False

    判断值是否不在列表,not in操作符:
    'a' not in a_list  //判断a是否不在列表中,并返回True或False

    统计指定值在列表中出现的次数,count方法:
    a_list.count('a')  //返回a在列表中的出现的次数

  • python xml 读操作

    2012-03-30 15:02:44

    1、导入库

    from xml.etree.ElementTree import ElementTree
    from xml.etree.ElementTree import Element
    from xml.etree.ElementTree import SubElement
    from xml.etree.ElementTree import dump
    from xml.etree.ElementTree import Comment
    from xml.etree.ElementTree import tostring
    '''
    <?xml version="1.0"?>
    <PurchaseOrder>
      <account refnum="2390094"/>
      <item sku="33-993933" qty="4">
        <name>Potato Smasher</name>
        <description>Smash Potatoes like never before.</description>
      </item>
    </PurchaseOrder>
    '''

    2、读文件的内容
    root=ElementTree(file='d:\\book.xml').getroot()
    print root.find('item/description').text
    print root.find('item').get('sku')
    print root.find('item').get('qty')

    3、输出想要的结果

  • python 链接oracle

    2012-03-29 11:31:34

    1、python 链接oracle 代码

    import cx_Oracle
    class Oracle():
        con = cx_Oracle.connect('system','tester','localhost:1521/ORCL')
        cursor = con.cursor()
        def select(self,sqselect):
            sqselect="""SELECT * FROM fang"""
            self.cursor.execute(sqselect)
            row=self.cursor.fetchall()
            print row[0][0]
            self.cursor.close()
            self.con.close()

        def insert(self,sqlinsert):
            sqlinsert=""" insert into fang values(10000,'fang',30) """
            self.cursor.execute(sqlinsert)
            self.cursor.close()
            self.con.commit()
            self.con.close()

        def update(self,sqlupdate):
            sqlupdate=""" update fang set id=110 where name='fang' """
            self.cursor.execute(sqlupdate)
            self.cursor.close()
            self.con.commit()
            self.con.close()

        def createtable(self,sqlcreate):
            sqlcreate=""" create table fang(id int ,name varchar(10),age int) """
            self.cursor.execute(sqlcreate)
            self.cursor.close()
            self.con.commit()
            self.con.close()

    oracle=Oracle()
    print oracle.select('')

    2、cx_Oracle 下载

    http://cx-oracle.sourceforge.net/ 

     

Open Toolbar