Xojo and load balancing with Haproxy

Xojo and load balancing with Haproxy

I have previously written a post on load balancing for Xojo web app developers using Nginx. You can see the post here. This is an update to that post focusing on Haproxy instead of Nginx. You can learn more about and download Haproxy here. Why choose Haproxy over Nginx? There are pros and cons to each of these solutions – but Haproxy offers better options for sticky sessions than the standard free Nginx package. If you get the Nginx “plus package” ($1350) then Nginx would be the better overall solution. But for free, Haproxy beats it for pure load balancing capability. Specifically, Haproxy includes cookie injection and routing which allows you to tag each user with a cookie indicating what back-end Xojo process to route them too – which maintains the session. Without the “Plus package” the best Nginx can do is IP hashing which will route an entire office of users (if behind one NAT IP) to the same single instance of your app. If you have multiple users in the same location (ex. employees of the same business) then the load balancing is defeated. If that is not your circumstance, then check out the Nginx post – it may be a better choice for you. Nginx can also offer the power of serving non Xojo web pages and static content such as images.   Haproxy Configuration global log 127.0.0.1 local0 maxconn 4096 daemon defaults log global mode http option httplog option dontlognull retries 3 option redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 frontend http-in bind *:80 acl is_myapp1 hdr_end(host) -i myapp1.mydomain.com acl is_myapp2 hdr_end(host) -i myapp2.mydomain.com use_backend myapp1pool if is_myapp1...
Cycles – the app.

Cycles – the app.

Check out Cycles! Cycles is a super-simple time and focus management utility for MacOS. It is SURE to make your life better immediately upon first use or your money-back…. GUARANTEED! (It’s free). I made this because I wanted a easy way to break down my work-time into 20 minute chunks where I can focus entirely on one task. Open up Cycles and it displays a small 20 minute count-down timer in the corner of your screen. When time is up it displays an alert (including FREE bonus motivational quote). Act now and I’ll thrown in a settings window where you can adjust the timer length.   Download the installer...
Xojo and load balancing with Nginx

Xojo and load balancing with Nginx

The following post is the results of some tests I did running a small cluster of Xojo apps on a CentOS server and load balancing them with Nginx. I am putting the summary in this post but there is additional discussion on the Xojo forum here and here. …… OK – so the results are in. Nginx load balancing made a MAJOR difference in usability, if an app is likely at all to get temporarily locked up (processing a large file or something). In the end, this works pretty much as I hoped and allows you to run separate instances of standalone apps across different processors and still keep the connections xojo needs to maintain sessions. Nginx Conf: upstream myproject { ip_hash; server 127.0.0.1:8080; server 127.0.0.1:8081; server 127.0.0.1:8082; #add a listing for any port you are running an instance on } server { listen 80; location / { proxy_buffering off; proxy_read_timeout 5m; proxy_pass http://myproject; } } ip_hash; is required to maintain session, app fails to launch without it. proxy_buffering off; needed to keep data flowing from app to client through proxy proxy_read_timeout 5m; keeps connection open for app “pings”. If left at default the app will disconnect after 60 seconds. I tried several settings between 1-10 minutes and this was the lowest setting that worked consistently. The app remains open. In order to start the app instances, I used upstart. I am on CentOS but this should also work on RHEL and possibly Fedora and many others. This is my method of choice because it will automatically respawn instances when they fail, allows easy starting and stopping of the whole group and can exec your app...
Batch Processing Images on Mac with SIPS

Batch Processing Images on Mac with SIPS

SIPS must be one of the simplest and most underrated ways to process images on the mac. I mean, that’s what it’s there for, but it’s like no one thinks about it. I was trying to resize about 500 jpegs today with automator and then I remembered it. SIPS is simpler and faster FTW! SIPS doesn’t do EVERYTHING, but it does some common functions quickly and nicely and it’s accessible from the command line right in the terminal. Here are some things SIPS can do: #Resize a batch of images to 250px (largest side) sips -Z 250 * #Resize only .jpg files in a folder to 500px x 500px - ignores aspect sips -z 500 500 *.jpg #Rotate a batch of images 90 degrees clock-wise sips -r 90 * #Resize down to fit 250 pixels and pad with white to make them square, add finder icon sips -Z 250 -p 250 250 --padColor FFFFFF -i * There are more things you can do with SIPS – be careful, don’t hurt yourself – SIPS modifies your files without apology so experiment on copies or live a life of regret. You can see the man page for more info. Of course, you could mogrify with ImageMagick, and that is truly wonderful, but not everyone needs or has IM and SIPS works out-of-the-box on any OSX Mac. BTW, SIPS stands for Scriptable Image Processing System, in case you were...
Appcelerator and Node.js

Appcelerator and Node.js

I hadn’t build an app in Titanium lately because I had been focusing on some other projects that were Xojo based. Some time had passed and I hadn’t even opened the IDE. Then a project came a long and I needed to pull out Appcellerator again and dust it off. I opened up a project where I had left it off. There was an update to Titanium to install – did that – cracked open my project and initiated a build to the iphone simulator – and ran into the following error: /usr/local/lib/node_modules/titanium/node_modules/longjohn/dist/longjohn.js:181 throw e; The app wouldn’t build – the command line tools would not work – total chaos. …turns out I had updated my Node.js installation for another project I was working on and Titanium did not like it. They prefer you use something in the 0.8.x family and I was at 0.11.4 so this was definitely not going to work. Luckily, there are already two very cool utility which make managing which version of node you are using really easy: n and nvm. I personally prefer n but nvm worked better in this case because my preferred shell is tcsh but Titanium’s is bash… nvm works great in bash, and for Titanium. Solution So – in a nutshell – the solution is install nvm, install Node.js v0.8.25 using nvm, make it the default node version and THEN run Titanium. Voila – back to normal! Something like this under bash: #get nvm curl https://raw.github.com/creationix/nvm/master/install.sh | sh #get an older node version nvm install 0.8.25 #use the new old version and set it as default nvm use 0.8.25...
Press-This 404 Issue

Press-This 404 Issue

I keep coming across an annoying issue with WordPress’ “Press-This” feature and I know I am not the only one. I am not sure of what the root cause of this is – if it is a Safari issue, a wordpress issue or a server configuration issue. Regardless, if you have been having difficulty with wordpress throwing a 404 whenever you use the bookmarklet you can try this simple fix which worked for me. javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://john-joyce.com/wp-admin/post-new.php',l=d.location,e=encodeURIComponent,u=f+'?u='+e(l.hostname+l.pathname)+'&t='+e(d.title)+'&s='+e(s)+'&v=4';a=function()%7Bif(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=810,height=570'))l.href=u;%7D;if%20(/Firefox/.test(navigator.userAgent))%20setTimeout(a,%200);%20else%20a();void(0) To use this, create a new bookmark and paste the above code into the URL or Location field.What’s different, you ask? All I changed is the encoding of the url, originally e(l.href) to the following e(l.hostname+l.pathname). This eliminates the “http://” portion which is what was causing the problem for...