Archive for the ‘Web Services’ Category

XMLRPC Server Slow in Python – How to Fix

Friday, February 19th, 2010

Background:
I had set up a Python XML-RPC server on one machine. When accessing the web services from other machines it would sometimes take up to 20 seconds to get a response. The strange thing was that this only happened when accessing the web service from some machines but not others.

Problem and Solution:
It turns out that Python’s BaseHTTPRequestHandler was trying to log the fully qualified domain name of each request’s IP address. Thus when we connected from machines that didn’t have a fully qualified domain name, it would take a long time to not find the FQDN. There is actually a bug for this.

Below is a simple fix that solved the problem for me (in Python 2.4). This would probably work in future versions too.

Assume this is your basic XMLRPC Server set up in Python:

import SimpleXMLRPCServer

class FuncGroup:
    """Just hold the funcs to be used in web service"""
    def hi(self,val):
        return "hi there"

#create server and start it
server_address = ('localhost',8000) # (address, port)
server = SimpleXMLRPCServer.SimpleXMLRPCServer(server_address)
server.register_instance(FuncGroup()) #reg. functions/class instance
server.serve_forever()


Here is the fixed version. I added in an override for the trouble function:

import SimpleXMLRPCServer

#new code
import BaseHTTPServer
def not_insane_address_string(self):
    host, port = self.client_address[:2]
    return '%s (no getfqdn)' % host #used to call: socket.getfqdn(host)
BaseHTTPServer.BaseHTTPRequestHandler.address_string = \
    not_insane_address_string
#end new code

class FuncGroup:
    """Just hold the funcs to be used in web service"""
    def hi(self,val):
        return "hi there"

#create server and start it
server_address = ('localhost',8000) # (address, port)
server = SimpleXMLRPCServer.SimpleXMLRPCServer(server_address)
server.register_instance(FuncGroup()) #reg. functions/class instance
server.serve_forever()

a MySQL Table of Zip Code Latitude/Longitude Coordinates

Saturday, November 1st, 2008

I was working on adding location awareness to GigBayes today and ended up making a table of zip codes and their coordinates. I figured it would be nice to share it with the world:

So here is a pre-made MySQL table containing US zip codes and their latitude and longitude (.zip 820K)

I got the data from here, and then deleted any zip codes which where missing coordinates.

You can also create this MySQL function to use for finding the distance between locations:

CREATE FUNCTION `earth_distance_miles`(p1 point, p2 point) RETURNS int(11)
RETURN
((ACOS(SIN(x(p1) * PI() / 180) * SIN(x(p2) * PI() / 180) + COS(x(p1) *
PI() / 180) * COS(x(p2) * PI() / 180) * COS((y(p1) - y(p2)) * PI() /
180)) * 180 / PI()) * 60 * 1.1515)

The formula comes from here.

You’d use the function like this:

SELECT earth_distance_miles(
(
SELECT location
FROM zip_code
WHERE zip = '06902'
), (
SELECT location
FROM zip_code
WHERE zip = '20905'
)
);

Which gives us 227 miles. A very reasonable answer.

Python’s SimpleXMLRPCServer – How to Serve from a Different Machine

Friday, September 14th, 2007

It turns out that following the example from Python’s SimpleXMLRPCServer documentation of serving from localhost only works for well, localhost:

from SimpleXMLRPCServer import SimpleXMLRPCServer
# Create server
server = SimpleXMLRPCServer(("localhost", 8000))
#snip ...(register functions here, see example)
server.register_instance(MyFuncs())
# Run the server's main loop
server.serve_forever()

To make your server available to other computers on your network you should do something like this:

import socket
from SimpleXMLRPCServer import SimpleXMLRPCServer
# Create server
server = SimpleXMLRPCServer((socket.gethostbyname(socket.gethostname()), 8000))
#snip ...(register functions here, see example)
server.register_instance(MyFuncs())
server.serve_forever()

Open question, will this work for serving to the internet at large, or do I need to do something differently? I’m actually not sure why localhost doesn’t work across the LAN. Does anyone know?

I found this answer by a google code search for SimpleXMLRPCServer.

Best Javascript IRC Chat Room

Tuesday, January 30th, 2007

Here’s the biggest one, the folks seem helpful:
Javascript IRC Chat on Freenode


Or you can find a lot more options with this search.

Google Reader doesn’t Refresh When You Tell it to

Sunday, January 14th, 2007

I’ve been noticing for a while that Google Reader is very delayed in showing me updates to feeds. I always figured it was my fault somehow, perhaps the specific feeds I was subscribed to?

But this thread and many others like it has everyone complaining of this problem. The best I can discern is that Google Readers refreshes feeds only on its own schedule (possibly as little as once every three hours!) and hitting the refresh button above the feed does nothing.

It was pointed out that this could be a bandwidth issue as in a lot of webmasters would get unhappy if (millions?) of Google Reader users were always hitting refresh and actually having Google re-access the feed. But I don’t want to hear excuses, I want an RSS reader that works! Timely updates are the killer app of RSS readers, get it fixed!

Can anyone reccomend a better web based RSS reader?

[tags]Google Reader, RSS, Atom, feeds, RSS reader, web based RSS reader[/tags]