Archive for January, 2009

IPv6 Setup

January 27th, 2009 1 comment

I received an email today from Jeremy Visser asking me how my blog is set up for ipv6. So intarwebs, here’s how my system works.

The server that hosts this blog is sitting in my living room connected via a router to Comcast cable Internet access. It runs a bunch of services, such as ejabberd for my xmpp server, postfix with courier for email, apache and PHP with Suhosin and XCache which hosts WordPress, mysql, and tomcat for whatever random Java webapps I’m playing with at the time.

All of the services are ipv6 enabled. For ejabberd, just add “inet6” to each listen socket. For postfix, apache, and mysql, no additional work was necessary. For tomcat, ipv6 support should work, but I run tomcat so it listens only to localhost, and access it via mod_proxy_ajp from apache, so I haven’t looked at that too much.

The router is an Asus WL-500gp running OpenWrt. Since Comcast doesn’t provide ipv6 address to their customers, I use a tunnel via aiccu (my tunnel type is “heartbeat” because my ipv4 address is dynamic). I then use radvd to advertise the ipv6 subnet to the other computers on the lan (such as my laptops and server). You can find a guide for how to get an ipv6 tunnel going on an OpenWrt at OpenWrt’s wiki.

Comcast blocks incoming port 25, so I can’t just run my mail server the simple way, unfortunately. To get aroud this, I have postfix listening for deliveries on a different port (8025), and I use Roller Network‘s “SMTP Redirection” service. I set the MX records for my domain to rollernet’s mail servers, then rollernet’s mail servers deliver the mail to my server on a different port. Currently, rollernet’s mail servers do not have AAAA records, but I have asked for this feature, and rollernet is usually pretty awesome, so I bet I’ll have ipv6 enabled incoming mail very soon. For outgoing mail, rollernet’s mail relay servers (which I have to use, as most mail systems automatically reject mail from personal ISPs as spam) try ipv6 delivery then ipv4; also, the relay servers do have AAAA records to my server sends mail using ipv6.

Rollernet also provides ipv6-enabled DNS services. I simply set my nameservers in my registrar to point to rollernet (rollernet’s nameservers are ipv6 enabled, which from what I understand, is rare), and start adding DNS records. I added AAAA records for my server, and clients without ipv4 connectivity can reach my web site entirely over ipv6. The same applies for XMPP.

I have certainly learned a lot about networking from my ipv6 experiment. First, most applications already support ipv6, and need no additional configuration, or at most, very little. Second, setting up an ipv6 server is not terribly hard; just get a tunnel, a subnet, and advertise it. Third, finding a DNS hosting service that is ipv6 enabled is very difficult – rollernet was the only one I could find when I started by search last year – I hope that situation improves soon. Of course, even if ipv6 DNS services do proliferate, I’m not switching away from rollernet, as their customer service is great, technical ability is outstanding, and pricing is unbelievable good. But that’s a story for another post.

And finally, I’m working on the Hurricane Electric IPv6 Certification.

IPv6 Certification Badge

IPv6 Certification Badge

Categories: Uncategorized Tags:

Preventing java.lang.OutOfMemoryError: unable to create new native thread

January 27th, 2009 2 comments

Artifactory is a Maven repository manager that does a lot of really useful things, such as cache maven artifacts (which saves external bandwidth and makes downloads faster) and stores our own artifacts (such as 3rd party software that can’t be on a public maven repository for licensing reasons). I recently upgraded from Artifactory 1.2 to 2.0.0, which was pretty painless.

The problems appeared the next day, when the application died with “java.lang.OutOfMemoryError: unable to create new native thread.” I tried a lot of things, but what worked was reducing the stack size. The JVM has an interesting implementation, the design of which I don’t completely understand, but the implication is that the more memory is allocated for the heap (not necessarily used by the heap), the less memory available in the stack, and since threads are made from the stack, in practice this means more “memory” in the heap sense (which is usually what people talk about) results in less threads being able to run concurrently.

To reduce the stack size, add “-Xss64kb” to the JVM options. I suggest you start with 64k, try the application, then if it doesn’t work (it will fail with a Java.lang.StackOverFlowError), increase the stack to 128k, then 256k, and so on. The default stack size is 8192k so there’s a wide range to test.

Also, on Linux, you’ll need to set the Linux thread stack size to the same value as the JVM stack size to get full benefits. To do that, use “ulimit -s <size in kb>”. In my case, Artifactory works great with a 128kb stack, so I used “-Xss128kb” for the JVM options and “ulimit -s 128” to set the Linux stack size. Note that the stack size applies per user, so you have to modify the init script, or edit /etc/security/limits.conf (on Debian/Ubuntu at least).

Categories: Uncategorized Tags:

UTF-8 and MySQL

January 22nd, 2009 2 comments

MySQL seems to operate in latin1 encoding by default, not in UTF-8, even though in many cases (such as most Linux distributions), the system uses UTF-8 for everything else by default. Today, this situation caused a confusing problem for me.

From 30,000 feet, the application is a Java web application that reads data from a MySQL database. The database is populated by a bunch of sql scripts (run via MySQL batch mode). Simple stuff. And all was good until we started using UTF-8 symbols, like ¢, ®, and ™ in the text in the scripts. These symbols came out all weird: instead of “¢” the page shows “¢”.

The first thing I checked was the encoding the .sql script files themselves were using. Turns out, they were stored as cp1251 (yay for Windows users). I used gedit to convert them to UTF-8 (there were only 4… if there were more, it would have been worth using iconv). Then I had to manually fix all the encoding errors in the files, which was time consuming.

Next, I checked the database itself. The tables were all stored in the latin1 character set with latin1_swedish_ci collation… so a quick alter table, and I was using the utf8 character set with utf8_general_ci collation.

I re-ran the scripts like this: mysql -hhost -uuser -ppassword < script.sql

And still… the site displayed the same, messed up characters.

I checked the documentation for MySQL Connector/J (the JDBC driver), and it says that the connection is UTF-8, and all should be fine. According to the browser, the server was returning UTF-8 data. Plus, I was seeing the actual UTF-8 symbols (¢ for example), just with extra garbage (Â) in front of them.

After much searching, I ran across the “default-character-set” parameter to the mysql command line client. It turns out that the command line client doesn’t detect the source file’s encoding using the byte order marker (BOM) or anything else, it just uses a default, which is usually latin1. So I changed my command, and tried again with: mysql -hhost -uuser -ppassword –default-character-set=utf8 < script.sql

And finally, the page showed everything correctly.

Categories: Uncategorized Tags:


January 21st, 2009 No comments

While browsing reddit today, I ran across X#, a programming language that describes itself as “an XML-oriented programming language designed to quickly create Web applications and services.” Looking over the samples, I have to agree with the reddit description: I can’t believe they are serious about this!

In my opinion, XML is a great data interchange format. There are tons of libraries available in probably every language (I bet even COBOL has one by now), it’s pretty easy to read, writing it isn’t too bad, and a huge amount of software uses it in some form or another (even MS Office uses it). I’m not saying that all XML is created equal, but I am saying that the concept and basics of XML seems pretty sound to me, and its advantages are many.

But XML as a programming language seems a bit loopy. X# is like Adobe Flex’s MXML: both promote the mixing of data and logic (in contrast to MVC architecture), both are verbose compared to more “normal” languages, and both may look easier to manipulate (“hey, it’s just XML, of course I can work with that!”) but in practice, they’re still programming languages.

I think there’s a chance that X# will take off in some specific areas, such as templating. But perhaps not; the X# implementors made a few not so ideal decisions which may limit that application.

  1. X# compiles to JVM bytecode using a custom compiler. The X# developers should have looked at JSR 223 and built a new script implementation for Java, making X# instantly available for any application that uses JSR 223 – and lots of applications do.
  2. X# has no API allowing it to be added to an existing application (at least, that I could find). For example, if I wanted to add X# as the view layer in my MVC application, how would I do that?
  3. X# can embed Java. This feature severely limits the potential for X# to become a more common language. For example, let’s say the X# team (or someone else) decides to implement an X# front end for the .NET CLR (via Mono). Ideally, any X# code in existence should seamlessly run on this runtime/compiler – but because the language spec includes the ability to embed Java, the Mono version of X# can never truly be called X#, because it can never embed Java.

Overall, I’m impressed with X#. Given some work, it could become a nice addition to the family of front end markup languages (like FreeMarker, Velocity, JSP, et al). And because it’s licensed under the GPLv3, perhaps it will mature. Best of luck, X# Team!

Categories: Uncategorized Tags:


January 16th, 2009 No comments

I was recently asked for my opinions on gTLDs (generic top level domains) – here are my thoughts.

  1. When a client runs a gTLD, there is (IMHO) a high cost (it’s $185k application + $75k/yr).
  2. What gTLD do you get? .integralblue, .integralblueinc, .ig, etc
  3. How do you use the gTLD, and tell people it’s a URL they can go to? Right now, if someone sees a string ending in .com, .net, or .org, they know they can enter that in their browser. For example, if I see a billboard that say “go buy stuff!” I know what to do. If I see “go buy stuff! www.integralblue” that’s just confusing. Where’s the .com? Perhaps that should use “http://www.integralblue” as the url? But that looks funny, and I bet users would still be baffled.
  4. There are a LOT of technical issues with gTLDs. The owner has to run DNS for a TLD, which is not technically trivial – and probably very expensive.
  5. I wouldn’t be surprised if a lot of software has problems with these TLDs (for example, link validity checkers, web crawlers, search engines, web browsers, email clients, etc)
  6. It’s not clear gTLDs will ever happen. The US government is not happy about it.
Categories: Uncategorized Tags: