Search Flex Components Free

Custom Search

December 10, 2007

Python PSYCO and PowerSDK SYNC

have been testing the PSYCO compiler with PowerSDK SYNC server and the results are pretty amazing. With minimal code changes, SYNC has jumped over 700% in core message processing speed.&

First let me explain PSYCO. PSYCO is a JIT(Just In Time) compiler that can be added to any Python distribution. When you enable PSYCO it caches functions in memory and every N+1 function call is executed in memory rather than within the Python interpreter. When the functions are run from the PSYCO cache the functions are nearly as fast as their C equivalent.

Python
PSYCO

This is a big deal as it makes a high level langauage like Python execute as fast as a compiled language but without all the hassle. The only drawback is that your application uses more memory in the caching of the functions. In tests with SYNC, it adds about 2MB of memory to a server application.

What is SYNC? SYNC is a server framework for real-time Flash applications written in Python. It allows you to design a protocol as a class and execute it within Python as a server.

Here is a sample SYNC server running an echo class on several ports:

import sync
import psyco
psyco.full()

class SyncEcho ( sync.Protocol ):
def onData( self , data ):
for c in self.clients:
c.send( data )

sync.enable( 'sync.powersdk.com', 80, SyncEcho )
sync.enable( 'sync.powersdk.com', 1568, SyncEcho )
sync.enable( 'sync.powersdk.com', 21, SyncEcho )
sync.start()

In the above example, the server runs the same class on 3 ports (80,1568,21) where any client can attach to any port and get identical data from a common server. SYNC makes writing optimized Flash XMLSocket servers from scratch really easy. The server does not use XML on the client or server and uses a similar model to Flash remoting to exchange data. You fire a client function which fires a server class function which fires a local event. Writing Flash clients for SYNC is a snap.

When PSYCO is applied to the server the onData method is cached in memory and run at near C speed in message threads. As message processing is cached in PSYCO, the server internals are dramatically faster. In tests, the server is over 7 times faster when PSYCO is added. Note the only changes to the application are "import psyco" and calling the "psyco.full()" method. That is just amazing to me.

I should have an example application posted today that uses the SYNC server and a fun Central application. I have been testing the server all week and think it is time to add lots of users onto the server to test scalability.

It would be really interesting to see Flash Player 8 add PSYCO-like functionality. If the player only had to interpret bytecode once and would execute functions directly from memory, AS execution would be dramatically (20x) faster and maybe faster than Java. Bye-Bye Processing, hello Flash.

Related Flex Tutorials