September 2015 Posts

Error No Buffer Space Available when Using Java, MyBatis and MySql

I’ve met a very weird error, that are not supposed to happen, when using MyBatis and MySql. Somehow my Windows OS is running out of ports, this is the complete stacktrace.

Caused by: java.net.SocketException: No buffer space available (maximum connections reached?): connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)]

I found out it happened because im using traditional unpooled connection, changing it into pooled connection in MyBatis solved it.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost/xxxx"/>
                <property name="username" value="xxxx"/>
                <property name="password" value=""/>
                <property name="poolMaximumActiveConnections" value="20"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>

    </mappers>
</configuration>
Google+

[Weird Issue] Slow Database Query Which only Happen in Windows Server 2008 64Bit

Several days ago, i was asked by my friend to fix one of his weird issue. A same java webapp deployed on two different Operating System, Windows Server 2003 32bit and Windows Server 2008 64bit, gives two different performance. The webapp runs well on Windows Server 2003, while at the same time have a very poor performance on Windows Server 2008. Same identical infrastructure, the only differences is the Windows Server version.

Later i will show you how to fix this issue, but first let me show what the infrastructure looks like. Basically, it’s a three tier infrastructure, a load balancer, multiple webserver and database server. At first, i thought that the bottleneck is on network infrastructure, but the network guy says that there is nothing wrong on network’s monitoring.

After several days monitoring, i found out that the main culprit is Windows Server 2008. Somehow there are some issues on network outbound causing a very slow database queries.

So this is to fix it, first via netsh interface

netsh interface tcp set global rss=disabled
netsh interface tcp set global autotuning=disabled
netsh interface tcp set global chimney=disabled

netsh1

netsh2

Next is disabling QoS Packet Scheduler,
qos

And last is adding a TcpNoDelay variable in windows server’s regedit, which located at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters
tcpnodelay

After i run those command and restart my machine, my application on Windows Server 2008 run smoothly.

Google+