Change of database: Percona Mysql to Postrgres for django

October 15th, 2011 alex No comments

Colleague of mine came with strange bug: 1. * i am opening python shell, and sending request User.objects.all() It returns valid information * then i’m adding user via web site * then i send request User.objects.all() again and new user is missing. If i will reopen shell then everything will be ok

  1. when i’m running “python manage.py test name_of_application” creating and deleting database takes too long Percona Server version: 5.5.15-55 Percona Server (GPL), Release 21.0 We decided that Postgres will be better and switched to it
Tags: , , ,
Categories: cloud Tags: , , ,

Monitoring rabbitmq server 2.5.1. with monit

July 15th, 2011 alex 2 comments

Simple task like setting up monitoring with monit for rabbit mq include two parts: 1) As discussed here Modify /etc/init.d/rabbitmq-server

  1. The following are added to the start function:
  2.   pid=`/usr/sbin/rabbitmqctl status | perl -n -e'/{pid,(\d+)/ && print
  3. $1'`
  4.   echo $pid > /var/run/rabbitmq.pid
  5. Right before:
  6.   echo SUCCESS
  7. The pid file is deleted within the stop function:
  8.          rm /var/run/rabbitmq.pid
  9. right after,
  10.          if [ $RETVAL = 0 ] ; then

2) Add this to monit configuration file:

  1. ### rabbitmq-server
  2. check process rabbitmq-server with pidfile /var/run/rabbitmq.pid
  3.      group rabbitmq
  4.      start program "/etc/init.d/rabbitmq-server start"
  5.      stop program "/etc/init.d/rabbitmq-server stop"
  6.      if failed port 5672 type tcp then restart
  7.      if 3 restarts within 3 cycles then timeout
Tags: , , ,

Django optimisation in production

July 10th, 2011 alex No comments

Few days ago I realised that my django installation in production started producing too many memory errors – thanks to monit memory alerts were filling my mailbox without any serious service interruption. But hundreds email messages daily annoyed me enough to look deeper into trouble.

Read more…

No tags for this post.
Categories: cloud, python, web Tags:

Secure Riak installation using n2n VPN

July 8th, 2011 alex No comments

Recently, I decided to have a closer look at Riak non-sql database, but found out that unlike CouchDB riak doesn’t have a HTTP basic auth implemented, or any other way of defining secure access to database.

I have three servers to build a cluster, but I feel very uneasy leaving open ports and full access to database to everyone in the world. The best practice guide here lists all ports necessary to secure riak installation, but messing with iptables didn’t feel like compelling idea.

So I decided to set up a VPN and only make riak nodes available on internal network inside VPN. Again, system administration is my hobby rather than the main job, so VPN installation should be straightforward and simple.

That’s how I found absolutely amazing product – n2n – Peer-to-Peer VPN network. I used svn version, but it is in standard ubuntu repos. I suggest install n2n network first, then configure cluster later(obviously I did it other way around,but you don’t have to repeat my mistakes). I successfully installed n2n on 3 Ubuntu Lucid 10.04.2 and Mac OS X Leopard and Snow Leopard.

1) Step 1. Prepare supernode (Linux):

sudo aptitude install uml-utilities #user mode utils
sudo tunctl -t tun0 # create tun0 interface
sudo aptitude install quilt libssl-dev #necessary libraries
svn co https://svn.ntop.org/svn/ntop/trunk/n2n #checkout trunk
cd n2n/n2n_v1/
make

So far everything straightforward.

Step2. Start supernode:

./supernode -l 1222 -v
“-v” indicate verbose output, supernode is a daemon, so no need to nhop etc.

Step3. On any other machine (not supernode), for linux follow step 1, create tun0 interface, then

  1. sudo ./edge -d tun0 -a new_node_internal_ip -c myVNPnetwork -k secretkey -l supernode_ip:1222 -v

For linux client “-d” is compulsory and should pass already created tun0 interface after that. new_node_internal_ip – new internal IP, my for example in range 10.0...

“-k secretkey” – you network encryption key. Should be common between nodes.

Then most important part – wait. Looking at verbose output of supernode and edge, edge should have:

"Registering with supernode"
Received REGISTER_ACK from remote peer [ip=*:1222]
for successful registration. Every time when you shutdown/restart edge or supernode it takes some time to re-register. Depending on the network it can take from few seconds to a few minutes. If you shutdown supernode, all clients should re-register, which can take up to 5 minutes.

Next repeat step 1 and 3 for other linux client for example. Do not try to install edge client on supernode until you have at least two other nodes and you can ping each other on internal ip. Replace “-v” with “-f” once configuration is fully functional.

If you want to add Mac OS X client, install tun/tap driver for mac os first from here, then

sudo ./edge  -a new_node_internal_ip -c myVNPnetwork -k secretkey -l supernode_ip:1222 -v

no need to pass parameter “-d”.

Now, assuming you have successfully installed at least two clients and have pinged each other over internal network, adding supernode computer as a node edge:

  1. sudo ./edge -d tun0 -a new_node_internal_ip -c myVNPnetwork -k secretkey -l supernode_ip:1222 -v -r

“-r Enable packet forwarding through n2n community” is important parameter here and that was the only way how I manage to add edge on supernode computer. This is enforces all packets to go via supernode ( Usually supernode acts only as an information exchange for other nodes, and encrypted connection formed between two edges directly ( remember it’s p2p network), but routing becomes messy if you connect edge node on same computer which runs supernode – other edge clients can’t see edge installed on supernode directly).

Supernode also acts as a router for a nodes behind NAT firewall.

All nodes should be fine and talking, we can go to Basic Cluster setup. For linux:

  1. wget http://downloads.basho.com/riak/CURRENT/riak_0.14.2-1_amd64.deb
  2. dpkg -i riak_0.14.2-1_amd64.deb
  3. sudo dpkg -i riak_0.14.2-1_amd64.deb

Then edit “/etc/riak/app.config” and “/etc/riak/vm.args”, put new (internal) IP addresses in appropriate places. If you already had riak installation,

  1. sudo riak-admin reip riak@old_ip riak@new_ip
  2. sudo riak-admin remove riak@127.0.0.1

and on other new riak nodes:

  1. ./bin/riak-admin join riak@10.0.*.2

Now you should have a secure riak cluster and in my case it is also spread across two datacenters and home. But you still may want to for a trial of Enterprise Riak if you are serious about deploying riak in production.

Tags: , , , , , , , , , , ,

Selecting mac ports python on mac (Leopard)

June 25th, 2011 alex No comments

Selecting python installed from mac ports on leopard works now like this:

  1. sudo port selectset python python26

Took some time to figure it out as most of the hints on the web don’t work

Tags: , , ,
Categories: cloud Tags: , , ,

Useful JavaScript one-liner for couchdb

June 1st, 2011 alex 1 comment

I found myself using more and more of this one-liner for working with couchdb database:

  1. var getNewDatabusUUID = JSON.parse($.ajax({ type: "GET", url: "/_uuids/",
  2.                 async: false }).responseText);
  3.  $.log("New uuid generated " + getNewDatabusUUID.uuids);

this example retrieves new uuids from couchdb, but I was using it to retrieve _rev of the document before deletion and similar one-off problems.

Tags: , , , , , ,
Categories: cloud, web Tags: , , , , , ,

Speeding up javascript: listing of elements from couchdb using jQuery mobile

May 15th, 2011 alex 1 comment

As I mentioned in my previous post I was using this tutorial as a basic for CRUD application for couchdb. But I found that listing of “albums” is very slow. I modified code using for loop examples from the book “High Performance Javascript” and results of the JS tests from gaperton livejournal. A lot of words for three line change: Read more…

Tags: , , , , ,

Checkbox and select elements in couch db

April 4th, 2011 alex No comments

If you wanted to make a select or checkbox element using mustache in couch db and trying to find example, here it is:

Read more…

No tags for this post.
Categories: cloud Tags:

Amazing examples of misuse of data mining in finance

March 26th, 2011 alex No comments

From stupid Data Mining Tricks: Overfitting S&P 500: “Norman Bloom, no doubt a champion of all data miners, went beyond trying to predict the stock market. Instead, he used the stock market, along with baseball scores, particularly those involving the New York Yankees, to “read the mind of God.”

I offer a small sample of Bloom, in the original punctuation, here: “THE INSTRUMENT GOD HAS SHAPED TO BRIG PROOF HE HAS THE POWER TO SHAPE THE PHYSICAL ACTIONS OF MANKIND–is organized athletics, and particularly BASEBALL. THE SECOND INSTRUMENT shaped by the ONE GOD, as the means to bring PROOF HE IS THE ONE God concerned with the Mental and business aspects of mankind and his civilization is the STOCK market—and particularly the greatest and most famous of all these – ie THE NEW YORK STOCK EXCHANGE.”

Full article here

  • Posted using BlogPress from my iPad
Tags: , , ,

Pingfire updated to work with Firefox 4

March 24th, 2011 alex 1 comment

I put firefox 4 on my wifes mac mini, so I spent some time trying to get pingfire extension working with FF4. Seems to be fine, drop me a comment or email and I may be will fix it :) Install pingfire

Tags: , , ,