Browse Source

made transformations 2 times faster

Simon Van Mierlo 9 years ago
parent
commit
b73e45e814
11 changed files with 50 additions and 28 deletions
  1. 1 1
      ___dataurize.js
  2. 1 1
      __worker.js
  3. 1 1
      csworker.js
  4. 1 1
      mt/httpd.py
  5. 2 2
      mt/mtworker.py
  6. 17 0
      mt/ptcal/accurate_time.py
  7. 5 5
      mt/ptcal/dapi.py
  8. 5 14
      mt/ptcal/ptcal.py
  9. 1 1
      mt/ptcal/tconstants.py
  10. 2 2
      mt/ws.py
  11. 14 0
      package.json

+ 1 - 1
___dataurize.js

@@ -25,7 +25,7 @@ exports.dataurize =
 	{
 		var request = 
 			require('http').request(
-				{'host':url.hostname || 'localhost', 
+				{'host':url.hostname || '127.0.0.1', 
 				 'port':url.port 		|| 80, 
 				 'path':url.path 		|| '/'},
 				function(resp)

+ 1 - 1
__worker.js

@@ -156,7 +156,7 @@ function __successContinuable(arg)
 
 
 /******************************* HTTP REQUESTS ********************************/
-/* make an HTTP request to localhost:port */
+/* make an HTTP request to 127.0.0.1:port */
 function __httpReq(method,url,data,port)
 {
 	if( port == undefined )

+ 1 - 1
csworker.js

@@ -608,7 +608,7 @@ with AToMPM.  If not, see <http://www.gnu.org/licenses/>.
 			var self = this;
 			return function(callback,errback)
 			{
-				var socket = _siocl.connect('localhost',{port:8124});	
+				var socket = _siocl.connect('127.0.0.1',{port:8124});	
 				socket.on('connect', 
 					function()	
 					{

+ 1 - 1
mt/httpd.py

@@ -159,7 +159,7 @@ class HTTPServerThread(threading.Thread) :
 
 
 	def run(self):
-		self.httpd = MultiThreadedHTTPServer(('', 8125), HTTPRequestHandler)
+		self.httpd = MultiThreadedHTTPServer(('127.0.0.1', 8125), HTTPRequestHandler)
 		self.httpd.serve_forever()
 		self.httpd.socket.close()
 	

+ 2 - 2
mt/mtworker.py

@@ -114,12 +114,12 @@ class mtworkerThread(threading.Thread) :
 	'''
 		send a request to this worker's asworker 
 		
-		TBI:: the use of 'localhost' implies that the atompm server is running on
+		TBI:: the use of '127.0.0.1' implies that the atompm server is running on
 	  			the same machine as the transformation engine... '''
 	def _aswHttpReq(self,method,uri,data) :
 		return utils.httpReq( 
 								method, 
-								'localhost:8124', 
+								'127.0.0.1:8124', 
 								uri+'?wid='+self._aswid, 
 								data)
 

+ 17 - 0
mt/ptcal/accurate_time.py

@@ -0,0 +1,17 @@
+import time as t
+import os
+
+global start_time
+def set_start_time():
+    global start_time
+    if os.name == 'posix':
+        start_time = t.time()
+    elif os.name == 'nt':
+        start_time = t.clock()
+
+if os.name == 'posix':
+    def time():
+        return int((t.time() - start_time) * 1000)
+elif os.name == 'nt':
+    def time():
+        return int((t.clock() - start_time) * 1000)

+ 5 - 5
mt/ptcal/dapi.py

@@ -46,7 +46,7 @@ class DesignerAPI :
 		
 	def _aswPrintReq(self,msg):
 		utils.httpReq(	'PUT', 
-						'localhost:8124', 
+						'127.0.0.1:8124', 
 						'/GET/console?wid='+self._aswid, 
 						{'text':msg})
 	
@@ -257,19 +257,19 @@ class DesignerAPI :
 
 
 	def _pauseTransformation(self):
-		self._httpReq("PUT", 'localhost:8125', '/execmode?wid='+self._mtwid, {'mode':'pause'})
+		self._httpReq("PUT", '127.0.0.1:8125', '/execmode?wid='+self._mtwid, {'mode':'pause'})
 		
 	def _stopTransformation(self):
-		self._httpReq("PUT", 'localhost:8125', '/execmode?wid='+self._mtwid, {'mode':'stop'})
+		self._httpReq("PUT", '127.0.0.1:8125', '/execmode?wid='+self._mtwid, {'mode':'stop'})
 		
 	def _resumeTransformation(self):
-		self._httpReq("PUT", 'localhost:8125', '/execmode?wid='+self._mtwid, {'mode':'play'})
+		self._httpReq("PUT", '127.0.0.1:8125', '/execmode?wid='+self._mtwid, {'mode':'play'})
 
 	def _httpReq(self,method,host,uri,data) :
 		if host == None :
 			return utils.httpReq(
 						method,
-						'localhost:8124',
+						'127.0.0.1:8124',
 						uri+'?wid='+self._aswid,
 						data)
 		else : 

+ 5 - 14
mt/ptcal/ptcal.py

@@ -27,6 +27,9 @@ from compiler import ModelAndRuleCompiler
 from pytcore.core.himesis import HConstants as HC
 from pytcore.rules.ndarule import NDARule
 from pytcore.tcore.messages import Packet
+from accurate_time import time as clock
+from accurate_time import set_start_time
+set_start_time()
 
 import cProfile, pstats, StringIO
 
@@ -47,8 +50,6 @@ from synchgraph import *
 from itertools import *
 #from petrinet import *
 from _abcoll import Iterable
-from time import *
-import timeit
 from pprint import isreadable
 from math import *
 
@@ -723,6 +724,7 @@ class PyTCoreAbstractionLayer :
                 seconds '''
     def play(self) :
 	
+        self.start_time = clock()
         if self._execmode == 'STOPPED':
             self._randomGen = Random(0)
         if self._execmode != 'PLAY' :
@@ -1013,19 +1015,8 @@ class PyTCoreAbstractionLayer :
             if mtc.nextInput == "packetIn":
                 startTime=clock()
                 
-                #pr = cProfile.Profile()
-                #pr.enable()
-                
                 self.packet = ar.packet_in(self.packet)
                 
-                
-                #pr.disable()
-                #s = StringIO.StringIO()
-                #sortby = 'cumulative'
-                #ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
-                #ps.print_stats()
-                #print s.getvalue()
-                
                 mtc.setLastStepExecTime(clock()-startTime)
                 
             elif mtc.nextInput == "nextIn":
@@ -1076,7 +1067,7 @@ class PyTCoreAbstractionLayer :
                         return
                     self._handleChangelogs()
                 
-                self._aswPrintReq(TC.TRANSFORMATION_DONE+nr['trafoResult']+" in "+str(self._mtContexts[-1].totalExecutionTime)+" seconds")
+                self._aswPrintReq(TC.TRANSFORMATION_DONE+nr['trafoResult']+" in "+str(self._mtContexts[-1].totalExecutionTime/1000.0)+" seconds, in total "+str((clock()-self.start_time)/1000.0))
                 self.stop()
                 return
             else:

+ 1 - 1
mt/ptcal/tconstants.py

@@ -34,7 +34,7 @@ class TConstants :
 	''' hergin :: motif-integration :: end '''
 
 	#inter-rule delay in PLAY mode
-	INTER_RULE_DELAY 		= 0.1
+	INTER_RULE_DELAY 		= 0.05
 	
 	#the delay between verifications that all changelogs pertaining to the last executed rule have been handled
 	WAIT_ON_CHLOG_DELAY	= 0.02

+ 2 - 2
mt/ws.py

@@ -64,14 +64,14 @@ class WebSocket :
 		2. open a websocket connection 
 		REF:: https://github.com/LearnBoost/socket.io-spec '''
 	def connect(self) :
-		conn  = httplib.HTTPConnection('localhost:8124')
+		conn  = httplib.HTTPConnection('127.0.0.1:8124')
 		conn.request('POST','/socket.io/1/')
 		resp  = conn.getresponse() 
 
 		if resp.status == 200 :
 			hskey = resp.read().split(':')[0]
 			self._ws = websocket.WebSocket(
-						'ws://localhost:8124/socket.io/1/websocket/'+hskey,
+						'ws://127.0.0.1:8124/socket.io/1/websocket/'+hskey,
 						onopen	 = self._onopen,
 						onmessage = self._onmessage)
 		else :

+ 14 - 0
package.json

@@ -0,0 +1,14 @@
+{ "name": "AToMPM",
+  "version": "1.0.0",
+  "description": "A Tool for Multi-Paradigm Modelling",
+  "bugs": 
+    {"url": "https://msdl.uantwerpen.be/git/simon/AToMPM/issues",
+     "email" : "simon.vanmierlo@uantwerpen.be"},
+  "repository" :
+      { "type" : "git",
+        "url" : "https://msdl.uantwerpen.be/git/simon/AToMPM"
+      },
+  "dependencies" :
+    {"socket.io" : "0.9.16",
+     "socket.io-client" : "0.9.16"}
+}