服务器情况:
节点个数:2
#! /usr/bin/python #coding=UTF-8 import cx_Oracle import time def hello(): '''Hello cx_Oracle示例: 1)打印数据库版本信息. 2)查询表数据.''' conn = cx_Oracle.connect("jscn/[email protected]:1521/jscn") cur = conn.cursor() try: print "Oracle Version:%s" % conn.version print "Table SUB_POLICY rows:" interger = 1 while interger <= 30000000: sql="select * from product PRODUCT_ID= '0lea940'" sql1="select * from productcategory where CATEGORY_ID='xhn6238'" cur.execute(sql) for row in cur: print row time.sleep(1) cur.execute(sql1) for row in cur: print row time.sleep(10) interger = interger + 1 finally: cur.close() conn.close() hello()
--切换到脚本所在的目录,执行以下命令 for /L %i in (1,1,50) do start "test %i" python test.py
Select spid ,Value / 1024 / 1024 Mb From V$session s, V$sesstat St, V$statname Sn, V$process p Where St.Sid = s.Sid And St.Statistic# = Sn.Statistic# And Sn.Name Like 'session pga memory' And p.Addr = s.Paddr and s.program='python.exe' Order By Value Desc;
呵呵,结束了,简单吧。
新的补充
今天把python脚本补充一下,之前一个进程一个连接,那我要测1000个连接,不是要启动1000进程吗?这样太恐怖了,是不要要多线程呢?当然要了,我们在更新一个python代码
#! /usr/bin/python #coding=UTF-8 import cx_Oracle import time import sys import logging import logging.config import threading from optparse import OptionParser def hello(): '''Hello cx_Oracle示例: 1)打印数据库版本信息. 2)查询表数据.''' conn = cx_Oracle.connect("jscn/[email protected]:1521/jscn") cur = conn.cursor() try: print "Oracle Version:%s" % conn.version print "Table SUB_POLICY rows:" interger = 1 while interger <= 30000000: sql="select * from product PRODUCT_ID= '0lea940'" sql1="select * from productcategory where CATEGORY_ID='xhn6238'" cur.execute(sql) for row in cur: print row time.sleep(1) cur.execute(sql1) for row in cur: print row time.sleep(10) interger = interger + 1 finally: cur.close() conn.close() def _handleCmdLine(args): parser = OptionParser() parser.add_option("--threadnum", dest="threadnum",action="store", type="int", default=10, help="thread num") (options, args) = parser.parse_args(args) return (options,args) class TestThread(threading.Thread): def run(self): while True: hello() def main(): options,args=_handleCmdLine(sys.argv) threads=[] for i in range(options.threadnum): th=TestThread() threads.append(th) th.setDaemon(True) th.start() for t in threads: t.join() if __name__ == '__main__': #logging.exception("main except") try: main() except Exception: logging.exception("main except")
在dos界面输入:
C:\Users\jscn-xw\Desktop>python test.py -h Usage: test.py [options] Options: -h, --help show this help message and exit --threadnum=THREADNUM thread num
C:\Users\jscn-xw\Desktop>python test.py --threadnum=300
现在已经进程就可以跑300个连接了。