0

I write scala application that use a lot of Kyotocabinet Db files (i need to open 500-3k little kyotocabinet files at one time).
But after 512 opened (created) db files i have a error "Error:success: no error", and new db file does not created.
After googling i found similar problem with Tokyo Cabinet + Java here: https://groups.google.com/forum/#!msg/tokyocabinet-users/ve6OsRm_hyU/hXC7795iqPsJ but without solution.
So what's the deal ? How can i open more kyotocabinet files in one application ? May be there is a some bug in Kyotocabinet ?

Vov Pov
  • 101
  • 5
  • Are you using Linux? Did you try to increase ulimit? – yǝsʞǝla Feb 25 '14 at 19:06
  • Yes i try to set ulimit -n 8192 in console before run test code in sbt, but there is no effect... I also think about mmap that Kyoto use for every open file, try to decrease msiz= param when open file, but this does not helped – Vov Pov Feb 25 '14 at 19:38
  • why would you need to open the database that many times? just open it when your program starts, and close it when it's done. – SnakeDoc Feb 25 '14 at 19:38
  • @SnakeDoc I don't try to open one database many times, i need to open many single different database files when application starts, and later. I understand that may be this looks little strange, but that the specifics of architecture. – Vov Pov Feb 25 '14 at 19:45
  • well, i know most OS's/Filesystems are going to have a maximum limit of how many open file handles there can be... sounds like you may be running into that, and if so, then it'd be a design problem. Those limits are there for a reason, and simply increasing them may lead to system instability, or worse. – SnakeDoc Feb 25 '14 at 20:05
  • @SnakeDoc Yes i know about that, but it try increase/decrease max open file parameter = no effect. Also i try to write simple application thath open >1024 files - and no error happend. So this is something kyoto specific.. – Vov Pov Feb 25 '14 at 22:02

2 Answers2

1

Ok it seems that i found the answer for my question...
This is not a Java or Scala specific issue but a Kyotocabinet
First i try to reproduce this behaviour in another language. So i writed test program using Perl , and it fails too, but with more informative message:
terminate called after throwing an instance of 'std::runtime_error'
what(): pthread_key_create

After that got sources of kyotocabinet and researched that for every kyoto File() object special TSDKey object created, and this object create pthread_key. By default one process can create limited number of this keys, and this number defined in PTHREAD_KEYS_MAX.
So it seems that open more than 512 kyoto db files in one process is not possible :(

Vov Pov
  • 101
  • 5
0

Yes, I did a try. Increasing the value of macro PTHREAD_KEYS_MAX will solve the problem.

I'm using Ubuntu 16.04, with libc version 2.23. libpthread is a add on of libc.

  1. Download source code from http://ftp.gnu.org/gnu/glibc/glibc-2.23.tar.bz2 .

  2. Modify macro PTHREAD_KEYS_MAX from 1024 to 2048. Don't be too large. I have tried 10240, but the test program crashed.

  3. Modify the maxcro value in system include file local_lim.h, and replace system libraries with your new version.

  4. Rebuild kyotocabinet.

  5. Copy libkyotocabinet.so and libpthread.so.0 to your test program path.

  6. export LD_LIBRARY_PATH=./

  7. Execute your test program. The number of max db files doubled.

James Feng
  • 184
  • 1
  • 14