SOAP, Background Tasks, and AJAXRecently in Rails I've been interacting with various SOAP services and running them in the background with Workling. I needed to relay the SOAP response to the client's web browser, so I decided to use AJAX to poll the status of my background tasks. This is great if you have < 30 second background tasks running, but don't want to block a user (and a request). The Solution
I created a Rails plugin, called AjaxTask, that has two components:
- Methods to use in your controller to define a task handler and create tasks
I've been running a mobile GPS tracking service, MoosTrax (formerly BlackBerry Tracker), for a few years and have encountered a large amount of data in the process.
A user's phone sends its location to the server and it is stored in a MySQL database. Each "location" entry is stored as a single row in a table.
Right now there are approximately 12 million rows in the location table, and things are getting slow now, as a full table scan can take ~3-4 minutes on my limited hardware. This means that if a user is pulling a location from history it could potentially block all other users (as the table is locked) access to the site until the query is complete.
Partitioning allows you to store parts of your table in their own logical space. With partitioning, you want to divide up your rows based on how you access them. If you partition your rows and you are still hitting all the partitions, it does you no good. The goal is that when you query, you will only have to look at a subset of the data to get a result, and not the whole table.
There are various ways in MySQL to partition a database, such as:
- RANGE - rows are partitioned based on the range of a column (i.e date, 2006-2007, 2007-20008, etc,.)
- HASH - hashes a column and depending on the result of the hash, has a different partition
- LIST, KEY
Choosing the partition type is important, so I looked at how my application looks up a user's location.
Getting a user’s current location
libactor is now available on google code. Check it out: http://code.google.com/p/libactor/
If you have any problems or ideas, post them there!
Check out some tutorials on various topics:
- Pylons Worker Threads
- CouchDB and Pylons, Getting Started
- CouchDB and Pylons: User Registration and Login
Recently I’ve been really interested in functional, concurrent programming languages, such as Erlang. This prompted me to have some fun in C, and try to implement a simple library that is based on the Actor Model.
Right now it is usable, although it may not be ready for production. It uses pthreads and the library handles all of the threading issues, so you don’t have to worry about any of it at all.
In a future version I plan to add more sandboxing to the actors, so that when one actor crashes, they don’t all go down!
Right now it supports the following:
- Spawn actor
- Sending messages
- Broadcast message
- Actor memory management convenience functions(when an actor dies, the memory is freed!)
Here is what a simple ping/pong example looks like:
There is a more detailed example in the source distribution, located in the examples/ directory.
You can get the source here. Please, let me know what you think about it, it was really fun to write!
Documentation is available here: http://chrismoos.com/libactordocs/