예제 #1
0
def scenBasic(options,user):

	with util.DbConn(const,user) as dbcon:
		with util.DbCursor(dbcon) as cursor:
			for iOper in range(options.iteration):
				params = util.getParameters(options,user)
				cde2 = prims.InsertOrder(params)
				cde2.execute(cursor)
	return
예제 #2
0
def storeOptions(prefix,results):
	""" store values only if keys are not written yet """
	with util.DbConn(const) as dbcon:
		with util.DbCursor(dbcon) as cursor:
			for k,v in results.iteritems():	
				if(not isinstance(v,int)):continue			
				name = prefix+'.'+k
				res = getSelect(cursor,'SELECT * FROM tconst WHERE name=%s',[name])
				if(len(res)==0):
					cursor.execute('INSERT INTO tconst (name,value) VALUES (%s,%s)',[name,v])
				"""
				else:
					cursor.execute("UPDATE tconst SET value=%s WHERE name=%s",[v,name])
				"""
	return
예제 #3
0
def simu(options):
	itera = 0
	
	#################################
	# Begin simu
	if(options.reset):
		if(not prims.initDb()):
			raise util.SimuException("Market is not opened")
			
	begin = util.getAvct(None)
	with util.DbConn(const) as dbcon:
		with util.DbCursor(dbcon) as cursor:
		
			util.writeMaxOptions(cursor,options)
			
			for user in util.nameUsers():
				prims.createUser(cursor,user)
				
			if(options.CHECKQUALITYOWNERSHIP):
				util.setQualityOwnership(cursor,True)
	
	##################################
	if((not scenarii.threadAllowed(options.scenario)) and options.threads>1):
		raise Exception("This scenario cannot be run in thread")
		
	_begin = util.now()
	if(options.threads==1):	
		user = util.nameUser(0)
		scenarii.simuInt((options,user))
	else:
		# run in theads		
		ts = []	
		for i in range(options.threads):
			user = util.nameUser(i)
			t = threa.ThreadWithArgs(func=scenarii.simuInt,args=(options,user),name=user)
			t.start()
			ts.append(t)
		for t in ts:
			t.join()
			
	itera = options.iteration * options.threads
	
	duree = util.duree(_begin,util.now())
	##################################
	# Terminate simu
	
	terminate(begin,duree,itera,options)
	return
예제 #4
0
def scenQuote(options,user):

	with util.DbConn(const,user) as dbcon:
		with util.DbCursor(dbcon) as cursor:
			for iOper in range(options.iteration):
				params = util.getParameters(options,user)
				cde = prims.GetQuote(params)
				cde.execute(cursor)

				if(cde.getIdQuote()!=0):
					cde2 = prims.ExecQuote(cde.getOwner(),cde.getIdQuote())
					cde2.execute(cursor)
				else:
					cde2 = prims.InsertOrder(params)
					cde2.execute(cursor)
	return
예제 #5
0
def testExec(options):
    with util.DbConn(const) as con:
        with util.DbCursor(con) as cursor:

            cursor.execute("SELECT count(*) from tuser where name=%s",
                           [const.DB_USER])
            res = [e for e in cursor]
            print res
            cursor.callproc("fgetconst", ["MAXORDERFETCH"])
            res = [e for e in cursor]
            print res
            try:
                cursor.callproc("fgetconst", ["MAXORDERFETCHAAAA"])
                res = [e for e in cursor]
                print res
            except StandardError, e:  # psycopg2.DatabaseError
                print "Exception:", sys.exc_info()
                print e.pgcode  # le code de l'erreur
                print e.pgerror
예제 #6
0
def terminate(begin,duree,itera,options):

	if(itera):
		res = util.getAvct(begin)
		res['dureeSecs'] = int(duree)
		res['nbOper'] = itera
		prims.storeOptions('results',res)
		prims.storeOptions('options',util.getDictInt(options))
		
		print '%i oper terminated after %.6f seconds (%.6f secs/oper)' % (itera,duree,duree/itera)
		
	with util.DbConn(const) as dbcon:
		with util.DbCursor(dbcon) as cursor:
			
			verifyVolumes(cursor)
		
			if options.maxparams:
				print "max_options:%s " % (util.readMaxOptions(cursor),)

			if(options.verif):
				util.runverif(cursor)
			
	return
예제 #7
0
파일: gen.py 프로젝트: joe2hpimn/openBarter
def test(cexec,conf,size):
    """
    truncate towner;
    copy towner from '/home/olivier/ob92/simu/liquid/data/towner.sql';
    truncate torder;
    copy torder(usr,ord,created,updated) from '/home/olivier/ob92/simu/liquid/data/torder_basic.sql';
    SELECT setval('torder_id_seq',1,false);
    truncate tstack;
    copy tstack from '/home/olivier/ob92/simu/liquid/data/tstack_basic.sql';
    SELECT setval('tstack_id_seq',10000,true);
    truncate tmvt;
    SELECT setval('tmvt_id_seq',1,false);
    """ 
    import util

    _size = min(size,cliquid.MAX_TORDER)
    fn = os.path.join(cliquid.PATH_DATA,'torder_'+conf.CONF_NAME+'.sql')
    gn = os.path.join(cliquid.PATH_DATA,'_tmp.sql')
    with open(fn,'r') as f:
        with open(gn,'w') as g:
            for i in range(_size):
                g.write(f.readline())
        
    with util.DbConn(cliquid) as dbcon:
		with util.DbCursor(dbcon) as cur:
		
		    cur.execute("UPDATE tconst SET value=%s WHERE name=%s",[cexec.MAXCYCLE,"MAXCYCLE"])
		    cur.execute("UPDATE tconst SET value=%s WHERE name=%s",[cexec.MAXPATHFETCHED,"MAXPATHFETCHED"])
		    cur.execute("UPDATE tconst SET value=%s WHERE name=%s",[cexec.MAXMVTPERTRANS,"MAXMVTPERTRANS"])
		    
		    cur.execute("truncate towner",[])
		    fn = os.path.join(cliquid.PATH_DATA,'towner.sql')
		    cur.execute("copy towner from %s",[fn])
		    
		    cur.execute("truncate torder",[])
		    cur.execute("copy torder(usr,ord,created,updated) from %s",[gn])
		    
		    cur.execute("truncate tstack",[])
		    fn = os.path.join(cliquid.PATH_DATA,'tstack_'+conf.CONF_NAME+'.sql')
		    cur.execute("copy tstack from %s",[fn])
		    cur.execute("SELECT setval('tstack_id_seq',%s,false)",[cliquid.MAX_TORDER+cliquid.MAX_TSTACK+1])
		    
		    cur.execute("truncate tmvt",[])
		    cur.execute("SELECT setval('tmvt_id_seq',1,false)",[])
		    
		    begin = util.now()
		    _cnt = 1
		    while(_cnt>=1):
		        cur.execute("SELECT * from femptystack()",[])
		        vec = cur.next()
		        _cnt = vec[0]
		    duree = util.getDelai(begin)
		    
		    duree = duree/cliquid.MAX_TSTACK
		    
		    cur.execute("SELECT sum(qtt) FROM tmvt",[])
		    vec = cur.next()
		    if(vec[0] is None): 
		        vol = 0
		    else:
		        vol = vec[0]
		    liqu = float(vol)/float(cliquid.MAX_TSTACK * cliquid.QTT_PROV)
		    		    
		    cur.execute("SELECT avg(s.nbc) FROM (SELECT max(nbc) as nbc,grp FROM tmvt group by grp) s",[])
		    vec = cur.next()
		    if(vec[0] is None): 
		        nbcm = 0
		    else:
		        nbcm = vec[0]
		        
		    cur.execute("SELECT avg(om_exp/om_rea) FROM tmvt ",[])
		    vec = cur.next()
		    if(vec[0] is None): 
		        gain = 0
		    else:
		        gain = vec[0]
		        
		    #print duree,liqu,nbcm
    
    print "test \'%s_%s\' performed with size=%i" % (conf.CONF_NAME,cexec.NAME,_size)        
    return  duree,liqu,nbcm,gain