The Real Life

Samstag, 22 Apr 2017

How to fix Too many files open in Tomcat

Not many Java programmers knows that socket connections are treated like files and they use file descriptor, which is a limited resource. Different operating system has different limits on number of file handles they can manage. One of the common reason of Too many files open in Tomcat, any Java application server is, too many clients connecting and disconnecting frequently at very short span of time. Since Socket connection internally use TCP protocol, which says that a socket can remain in TIME_WAIT state for some time, even after they are closed. One of the reason to keep closed socket in TIME_WAIT state is to ensure that delayed packets reached to the corresponding socket. Different operating system has different default time to keep sockets in TIME_WAIT state, in Linux it’s 60 seconds, while in Windows is 4 minutes. Remember longer the timeout, longer your closed socket will keep file handle, which increase chances of Too many files open exception.

This also means, if you are running Tomcat or any other web server in windows machine, you are more prone to this error than Unix based systems.

By the way this error is same as Too many files open exception, which is throw by code from IO package if you try to open a new FileInputStream or any stream pointing to file resource.

Now, we know that this error is coming because clients are connecting and disconnecting frequently. If that’s seems unusual to your application, you can find the culprit client and prohibit them from reconnecting from making a connection, but if that is something, your application may expect and you want to handle it on your side, you have two options :

1) Increase number of open file handles or file descriptors per process.
2) Reduce timeout for TIME_WAIT state in your operating system

In UNIX based operating system you can use command ulimit -a to find out how many open file handles per process is allowed.

$ ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 10
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 2048
virtual memory (kbytes, -v) unlimited

You can see that, open files (-n) 256, which means only 256 open file handles per process is allowed. If your Java program, remember Tomcat or any other application server are Java programs and they run on JVM, exceeds this limit, it will throw Too many files open error.

You can change this limit by using ulimit -n to a larger number e.g. 4096, but do it only if you are know what you are doing.

Another important thing to verify is that, your process is not leaking file descriptors or handles, well that’s a tedious thing to find out, but you can use lsof command to check how many open file handles is owned by a particular process in UNIX or Linux. You can run lsof command by providing PID of your process, which you can get it from ps command.

Similarly, you can change TIME_WAIT timeout, as a really low time means, you might miss delayed packets. In UNIX based systems, you ca n see current configuration in /proc/sys/net/ipv4/tcp_fin_timeout file. In Windows based system, you can see this information in windows registry. You can change the TCP TIME_WAIT timeout in Windows by following below steps :

1) Open Windows Registry Editor, by typing regedit in run command window
2) Find the key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\tcpip\Parameters
3) Add a new key value pair TcpTimedWaitDelay asa decimal and set the desired timeout in seconds (60-240)
4) Restart your windows machine.

Bottom line to fix Too many files open, is that either increasing number of open file handles or reducing TCP TIME_WAIT timeout.


Donnerstag, 25 Feb 2016

PortsCamp Malaysia

A quick statement regarding MyPortsCamp thing :).

When my old friend Marcelo Araujo told me all about Taiwan PortsCamp, I was really excited. I was even more excited when I saw the pictures and heard the outcome of it.

I was told that it was very successful. I’ve shared from day one in our Telegram mybsd group, that I love the idea :). The other day there was a discussion again in the group on learning more about FreeBSD and ports. I pointed out that I would like to see some contributors or committers from Malaysia. Currently I am the only one from here and I am not even local :(.

I had a conversation with Mohd Fazli Azran, who is well known for his OpenSource passion and support around here. He posted on Facebook a question if anyone would want to become my “protege” to learn more about ports, how to do things, etc. To my surprise, the feedback was quite good. I reminded him about Taiwan PortsCamp and that I love the idea to see it happening here in Malaysia. Fazli created an FB Event to find out how much interest this event could gain, and the teaser will run till the end of next week, Friday March 4th. After that we will decide if the event will be organized here. The target is to find at least 20 people who are interested.

What is PortsCamp?
This is a community event where FreeBSD committers help people to understand what are ports and how to package new software to submit it as a new port.

The Basic idea
The Ports System used in FreeBSD is dead simple. It should be easy for any open source software publisher to submit their code to FreeBSD. But they just don’t know how simple it is, so we are gonna show them.

That’s it!


Donnerstag, 18 Feb 2016

Future of pecl ports


First of all I’d like to thank for all the feedback I got of over the last few days, I really appreciate it so much. Even though php70 in the tree, and most issues reports have been fixed, we can not stop making progress. There is still MUCH to do. I have started a discussion where I’d like to invite everyone to join, it’s about the future of our pecl ports and how we want to move on to support pecl and php7 🙂

Please join us 🙂


Montag, 15 Feb 2016

php7 now in ports!


I just added php7 to the ports

Welcome php 7.0.3


I’d like to thanks:
Kurt Jaeger
Matthias Breddin
Rainer Duffner
Victor van Vlaardingen
Torsten Zuehlsdorff
Franco Fichtner
and all helpers and testers from ports at .


Mittwoch, 13 Jan 2016

Taiwan PortsCamp

I just came across, that there will be a PortsCamp hold in Taiwan.

This is a community event where FreeBSD committers help people to understand what are ports and how to package new software to submit it as a new port.

The Basic idea

The Ports System used in FreeBSD is dead simple. It should be easy for any open source software publisher to submit their code to FreeBSD. But they just don’t know how simple it is, so we are gonna show ‚em.

You can find more infos here.

Personally I really love this idea, and wish all my Friends over there a good success and most impotently a lot fun :).

Who knows maybe I’ll be joining the next event!


Dienstag, 12 Jan 2016

[CFT] php7 for FreeBSD


I have spent the last few days on getting php7 ready for FreeBSD.
The initial work was done by Senta Ltd [1] via github. I picked up what’s
left from there and finished up all missing ports and cleaned up a lot of mess.

So far everything that is related to php7 works for me. Pear and pecl ports are
still untested but I’ll look into them after php7 has landed in ports, in order to
please the majority. If you have the time it would be very much appreciated if
you can test them and send me some feedback.

You can find all the ports here

In case you are still using phpX-mysql, you have to replace it with mysqli.

Whats New in PHP7

Have fun 🙂

– Miwi


Mittwoch, 6 Jan 2016

FreeBSD needs you!

Oh well, it’s time to renew our job offer to you. Of course it’s all
for free, and you can’t earn any money out of it, but you’ll get a
big thanks, hugs and love from the community. Ask yourself, how
long have you been using FreeBSD. Months? Years? Decades? And you
love using it because of whatever reason but at the same time
you’re feeling a bit guilty to use it all for free without giving
anything back? Well now you’ll have the chance to change that.

We at FreeBSD are always in need of new people who are willing
to spare some of their time and effort into contributing to FreeBSD.

Let me share some of my experience. I have (re)built a lot of
teams in the past, such as gecko@, kde@, python@, and I was
involved in the creation of FreeBSD vbox@ team. Now a few years
later, things are better but still not as active as we would like them.
Most of our port teams still need more members. We would very
much appreciate to see some new contributers and testers. :).

Okay, most of these need an understanding of programming and
scripting. If you think that you can’t do any of that, testing would
also help much. FreeBSD is one of the best documented open source
project, so that’s another area that could use some help too. Check
if is available in your language, or start helping to
improve the FreeBSD documents in your language. It would be very
helpful and the community will thank you for that. So if you would
like to offer some help, ping us on IRC. 🙂

– Martin


Dienstag, 5 Jan 2016

[CFT]Centos 6.7 userland update.


First post in 2016 🙂 this is a Call For Testing (CFT) of our new Centos 6.7 userland update.

This update includes a lot of fixes, including Skype which has been broken for a few months now. We’d like your feedback about performance and experience of general usage like Flash, or any games that require Linux Emulation. This update comes of course for with 32bit and 64bit variants.

To test the 64-bit version [1], add the following to /etc/make.conf:


[1] NOTE: Skype will *NOT* work with the 64-bit version, as it is a 32-bit binary

There are two ways to apply the update

1) If your ports tree is a portsnap checkout, ensure its up to date and run
following commands.

cd /path/to/your/ports tree
patch < D3428.diff
find . -name '*.orig' -delete

2) If your ports tree is a svn checkout, ensure its up to date, and you have devel/php5-arcanist installed and a account here (For more infos about review please click here. run
following commands.

cd /path/to/your/ports tree
arc patch D3428

It will update all related ports.

That’s it, you can run a normal portmaster or portupgrade upgrade upgrade, or just install any Linux port you like :-).

There is a known plist issue with x11-toolkits/linux-c6-qt47-x11, which
has no impact for testing but we are working on it.

Thanks for your time and testing all your feedback is welcome 🙂

Have fun 🙂


Mittwoch, 30 Dez 2015

FreeBSD 10 autotools hack

First of all, WOW it’s been a long time since I wrote something here.. 🙂

For a few months now I’ve been back working on Ports and my todo list is already VERY VERY long .. but that’s a topic for 2016 which I’ll post about another time. Right now I want to share some other discoveries I made the other that day cause me concern.

Back in 2011, we added a workaround to fix an autotools problem with FreeBSD 10 you may remember that fiasco. Last year in December, @bapt and @antoine revisited updating autotools and the fallout was terrible. More than 9000 ports were skipped when there both tested it.

A year later, on my return to FreeBSD, I’ve started looking back at my old „portmgr todo list“, and thought it would be a good idea to look at autotools again. A quick check showed that the situation today is not any better (thanks antoine for grepping the build logs). When you look at file, you will probably realize that list of ports is long, yes, about *3 thousand ports* long, whos patches have never been sent upstream. These workarounds have existed in the ports tree for almost 4 years now. We need to change that, we need to remind maintainers and upstreams to get it fixed. If you are a maintainer of any of those ports, please report this to the upstream. Your help in achieving that is very welcome.

If you need any help or have any question you can find me on irc efnet/#bsdports freenode/#freebsd-ports. If I am not around those peoples there are also very helpful :).

So long miwi


Donnerstag, 7 Jun 2012

[CFT] Xorg 7.7 ready for testing!

Hi Fans,

The FreeBSD Xorg Team is pleased to announce Xorg 7.7 Release. We are very happy to be able to Call for testing shortly after the Xorg team annouced 7.7 release. This CFT is also open for discussion on how we should move forward with xorg release as we are facing some issues and we would like to ask for your opinion. Right now we have 2 existing xorg versions in our Ports Tree. The situation is quite bad due to our poor graphic card support. That means we do not have much choice but to take it as how it is now. But with regards to mesa support, we have to face some new challanges.

With the new mesa 8.0 release, accelerated support for a number of older graphic cards was dropped. At the moment we are not sure how to deal with that.We are thinking of just replacing mesa 7.11 with 8.0 or making a new flag like WITH_MESA= 7.11.2 / 8.0 in combination with WITH_NEW_XORG, and let the mesa 7.6.1 set as default together with the old xorg version. Obviosly the latter option make the already complex situation more complex. The problem is, users, especially  the new ones can easily get confused with it. Another issue is, the packages.We can’t deliver a package set with the new Xorg releases. This means users with new hardware will have to compile everything by themselves. Though I’m totally fine with compiling, not everyone has the CPU power to compile everything. What I’m trying to say is, I would love to see the newer xorg released as the default version, but i know this will break a lot of old hardware. The thing is, when we want to try to become a Modern Operating System, I dont see any other way to make the new xorg as default but to give Users the chance to compile the old xorg with a flag like WITH_OLD_XORG.

Some notes regarding KMS support:
KMS Support has been completely migrated to FreeBSD 10. The MFC to 9 will come soon, that means so long its not MFC’d to 9-Stable, users need to get the latest patch from our x11 mailing list.

This testing includes
* libdrm 2.4.34 (including KMS support)
* mesa 8.0.3
* full Xorg 7.7 release

Checkout Xorg Development Repo:
You will need to install devel/subversion in order to checkout the xorg repo. Next, you will need to add WITH_NEW_XORG=yes in your /etc/make.conf if you want to try out the new Xorg and mesa. Note
that if you are not qualified for the KMS patch, you shouldn’t use WITH_NEW_XORG=yes because the old intel driver doesn’t build with the new X server. If you are qualified, you should also set WITH_KMS=yes
in /etc/make.conf. Nvidia and ATI users should set WITH_NEW_XORG=yes.

svn co

A small merge script to merge the svn checkout into the real portstree can be found here:

The script is a modified version of the old kdemerge script. Please set the KDEDIR variable to the path of your ports. After merging, run one of the following command, depending on which
tool you use to manage your installed packages.

portupgrade -af \*
portmaster -a

After installing these, you will have to rebuild all xf86-* ports. We will bump all releated ports during the commit to the ports tree.

Our current plan is to let the CFT running for a while, and see what the outcome of the discussion above is. We hope to get a lot of feedback to solve as many problems as possible. Also we are working on the
libglut to freeglut migration, this will definitely complete before we import Xorg 7.7. So we still have enough time.  We are looking forward for your feedback.

– miwi on behalf of the FreeBSD X11 Team