Dysthymia

With dysthymia, you may lose interest in normal daily activities, feel hopeless, lack productivity, and have low self-esteem and an overall feeling of inadequacy. People with dysthymia are often thought of as being overly critical, constantly complaining and incapable of having fun.

While I’ve made this web site mainly technical over the past few years, the domain name is still james.roomfullofmirrors.com (jrfom.com is the short form). If I don’t write about myself at least occasionally, then the domain name means nothing. If that’s not why you read this site, then you may want to skip this post. Also, this post may ramble a bit…

A month ago I went to my doctor for a routine check-up. While there, I asked him how often is it normal for someone to feel depressed. He asked me a series of questions and diagnosed me with dysthymia (now persistent depressive disorder). I had never heard of this disorder before that diagnosis. He prescribed Escitalopram to me, along with some other suggestions, and I’ve been taking it over the past month (starting the full dose every day tomorrow). It is said the drug can take up to six weeks to really take effect, but I feel that it has already made a tremendous difference. So I am writing this post to raise awareness of this disorder, as I think it may be more prevalent than the statistics claim. Everyone has heard of stuff like bipolar disorder, but dysthymia less so.

Of all the definitions I have read for dysthymia, the quote that leads off this post, from mayoclinic.org, strikes me the most. It sums up me in two short sentences. As I described it to my doctor, I have felt, for as long as I can recall, that I have had to fight off these feelings, or try to correct these behaviors, every single day. It got to the point that I was physically exhausted and mentally drained from the struggle, and just could not go on without asking a professional’s opinion. There’s just no way that is how everyone feels all the time.

Prior to this medication, I had reached the point where I did not care about a single thing. I went through my daily motions just to keep on existing, and no amount of distractions (“toys” as I’ve called them, e.g. video games or synthesizers) helped to pull me out. For example, I’d sit at work, pushing myself to do whatever needed to be done there, and daydream about going home and working on music. But by the time I got home, laying on the couch and watching pointless television until time to go to bed was way more appealing.

Occasionally I would succeed in working on music. And I think you can hear the dysthymia in my music; particularly in my most recent releases. It doesn’t matter if the songs are in a Major key, they all have some tinge of, erm, darkness to them. Truly, that’s the style of music I enjoy the most, but have I found the reason? I don’t know the answer to that yet.

But now that I’m on the medication, it’s like a different world. I feel, for lack of a better word, normal. I wouldn’t say I’m necessarily happy, I’m not, really. That’s not what the medication is supposed to do. But I do feel more eager to do things (whether I do them or not; laziness is laziness), and have been much more productive than I have been in a long time. Before, I felt like there was a seething rage just barely contained that would unleash itself with little prompting. Now, that is gone; it’s inexplicable other to say that it’s just “gone.” Yes, I get agitated and a little angry still, but nothing like before. It has been a part of me for so long I think I almost miss it, but not really. It was the most draining part, and the part that hurt my personal relationships the most.

I’m scheduled to visit my doctor for a follow-up in three and a half weeks. Maybe the medication will have other effects by then. Or maybe he’ll ask me to try something different. I don’t know. I just know that right now, today, I feel like a corner has been turned. I feel like I can advance, and that I’m not stuck in a swamp of sadness; the luck dragon has descended and snatched me up.

If any of this post resonates with you, either personally or by reminding you of someone you know, I urge you to ask a professional about it (or urge that someone you know to do so). Living with persistent depressive disorder, if that is indeed what I have (and I do believe that to be the case), is an awful way to live.

HAProxy With Keepalived For Fail Over

There are plenty of articles on the web that detail setting up HAProxy and Keepalived to create a load balancer with failover support. So why write another one? There are a couple points that I didn’t find addressed in my research; at least, not clearly. They are:

  1. How do the load balanced IP addresses get managed?
  2. What ports need to be open in the load balancers firewalls?

Instead of simply answering those questions, and making you learn the other details elsewhere, I will answer them in a full write up of a simple scenario:

  1. We have services foo.example.com, bar.example.com, and baz.example.com
  2. foo.example.com has a “public” IP 10.0.0.1 and is provided by private IPs 192.168.1.5 and 192.168.1.6
  3. bar.example.com = 10.0.0.2 provided by 192.168.2.5 and 192.168.2.6
  4. baz.example.com = 10.0.0.3 provided by 192.168.3.5 and 192.168.3.6

We’re going to setup one instance of HAProxy to load balance all three services in Virtual Machine 1 (VM1), and a second instance in VM2 to provide a fail over for VM1 (or real hardware, whatever).

Note to Red Hat users: I have a repository available that makes building HAProxy and Keepalived RPMs trivial. You can reach it at https://github.com/jsumners/failover-lb.

HAProxy

I’m not going to spend much time on the HAProxy configuration. There are many, many, well documented options for HAProxy and your actual scenario may extend beyond this simple one. If suffices to say that the following configuration will look for any traffic coming into the currently active VM (VM1 or VM2) on the public IPs 10.0.0.1, 10.0.0.2, and 10.0.0.3 on port 80. It will then proxy said traffic to one of the private servers according to the round robin load balancing algorithm and/or a cookie denoting the destination server.

global
  log 127.0.0.1   local0 debug debug
  maxconn 4096
  chroot /var/lib/haproxy
  pidfile /var/run/haproxy.pid
  user haproxy
  group haproxy
  daemon
  #debug
  #quiet

  stats socket /var/lib/haproxy/stats mode 600 level admin

defaults
  log global
  mode    http
  option  httplog
  option  dontlognull
  option  http-server-close
  option  forwardfor except 127.0.0.0/8
  option  redispatch
  option  httpclose
  retries 3
  maxconn 3000
  timeout http-request 10s
  timeout queue 1m
  timeout connect 10s
  timeout client 1m
  timeout server 1m
  timeout http-keep-alive 10s
  timeout check 10s

listen foo-http
  bind 10.0.0.1:80
  balance roundrobin
  cookie foo-server-id insert indirect nocache preserve maxidle 1h maxlife 1h domain .foo.example.com
  # proxy to port 80 and set foo-server-id cookie to "foo1"
  server foo1-http 192.168.1.5 cookie foo1
  # proxy to port 8080 and set foo-server-id cookie to "foo2"
  server foo2-http 192.168.1.6:8080 cookie foo2
  
listen bar-http
  bind 10.0.0.2:80
  balance roundrobin
  cookie bar-server-id insert indirect nocache preserve maxidle 1h maxlife 1h domain .bar.example.com
  server bar1-http 192.168.2.5 cookie bar1
  server bar2-http 192.168.2.6 cookie bar2
  
listen baz-http
  bind 10.0.0.2:80
  balance roundrobin
  cookie baz-server-id insert indirect nocache preserve maxidle 1h maxlife 2h domain .baz.example.com
  server baz1-http 192.168.3.5:8080 cookie baz1
  server baz2-http 192.168.3.6:8080 cookie baz2

Keepalived

Keepalived will be managing the fail over duties for us. It does this by:

  1. Running a script to check if a managed service is running
  2. Managing the public IP addresses for our services via IPVS
  3. Monitoring the status of a sister Keepalived process via VRRP

For our scenario, the Keepalived configuration would be:

vrrp_script chk_haproxy {
  script "killall -0 haproxy" # verify the pid existence
  interval 2 # check every 2 seconds
  weight 2 # add 2 points of prio if OK
}

vrrp_instance VI_1 {
  interface eth0 # physical interface that is connected to the network
  state MASTER
  virtual_router_id 51
  priority 101 # 101 on master, 100 on backup
  virtual_ipaddress {
    10.0.0.1 # foo.example.com
    10.0.0.2 # bar.example.com
    10.0.0.3 # baz.example.com
  }
  track_script {
    chk_haproxy
  }
}

Note that this is the only place on the system where we declare that the IPs 10.0.0.1, 10.0.0.2, and 10.0.0.3 will be managed by the kernel. We don’t declare them in a /etc/network/interfaces (Debian), /etc/sysconfig/network-scripts/ifcfg-eth0:{1,2,3} (Red Hat), or other configuration file. When Keepalived launches, it will register the IP addresses with the kernel on the physical interface eth0.

Also note that we are configuring Keepalived to verify that HAProxy is running by checking for an HAProxy process identifier every two seconds. If it doesn’t find a PID, it won’t increase the VM1’s priority, VM2 will/should increase its priority, and VM2 will take over (at which point the IPs on VM1 will be released).

Finally, for the VRRP polling to work, we simply need to make sure VM1 and VM2 accept VRRP broadcast traffic:

$ iptables -A INPUT -p vrrp -d 224.0.0.0/8 -j ACCEPT

BuddyPress And Lighttpd

This is a short post that detailing how to fix a problem with the WordPress plugin BuddyPress and Lighttpd.

The problem in question:

Users that register for a site via BuddyPress are sent an email with an account activation link. Upon visiting said link, their account is supposed to be activated thereby verifying their email address. However, with the typical configuration for a WordPress site on Lighttpd (redirecting all 404s to “/index.php”), GET request parameters are not forwarded (as they shouldn’t be, really). Since BuddyPress relies on a GET parameter for the activation key (and it should not do so) this breaks the activation process.

Solution:

The solution to this problem is to catch requests for activations and directly process them through the index.php routing handler. To do so, add an extra bit of configuration to your Lighttpd configuration for the site:

url.rewrite-final = (
  # Enable redirects for account activations that use a GET parameter
  "^/register/activate-account(.*)$" => "/index.php/$1"
)

Note that “/register/activate-account” is local to your BuddyPress configuration. It should match the URL you have configured for said action (i.e. look at an activation email to figure out what to look for).

References:

http://buddypress.org/support/topic/activation-not-possible/
http://redmine.lighttpd.net/issues/660
http://www.crobak.org/2011/01/moving-wordpress-blog-to-lighttpd/

Oracle JDBC PermGen Memory Leak Fix

Let’s talk about the Oracle JDBC drivers. If you have had the misfortune to use them, you know that there are many ways they can taint your well written application. For me, the most annoying problem is the memory leaks they leave behind when you redeploy an application without shutting down the JVM instance. Do this enough, and the drivers end up using all of the PermGen space and necessitating a restart of the JVM (undesirable when your JVM is really a web server running multiple applications). This problem has plagued me for a couple of years, and I think I have finally figured out the solution. I wrote that solution into a library I call SimpleOraclePool.

SimpleOraclePool takes care of creating a connection pool using the Oracle UCP library with the Oracle JDBC driver providing the connection. Included in the library is a ServletContextListener, named OjdbcDriverListener, that will clean up the Oracle mess when your application is unloaded (from a Servlet container, of course).

I’ll leave out the explanation of how to use it. That is all documented in the code repository’s readme and the JavaDoc included with the library. But I would like to sign this post with a message to Oracle:

....................../´¯/) 
....................,/¯../ 
.................../..../ 
............./´¯/'...'/´¯¯`·¸ 
........../'/.../..../......./¨¯\ 
........('(...´...´.... ¯~/'...') 
.........\.................'...../ 
..........''...\.......... _.·´ 
............\..............( 
..............\.............\...