Posted on 2 Comments

thread_stack_size in my.cnf

Many configs have thread_stack_size configured explicitly, but that can cause rather bad trouble:

  • if the stack inside a thread it’s too small, you can get segfault crashes (stack overflow, essentially). Particularly on 64-bit.
  • if the stack is too large, your system cannot handle as many connections since it all eats RAM.

Let mysqld sort it out, on startup it does a calculation based on the CPU architecture, and that’s actually the most sensible. So for almost all setups, remove any thread_stack_size=… line you might have in my.cnf.

Posted on 2 Comments

2 thoughts on “thread_stack_size in my.cnf

  1. If there’s a calculation done on startup, what does it mean that there is there a default value of 192k?

    As the docs say – http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_thread_stack

    “The default (192KB) is large enough for normal operation. If the thread stack size is too small, it limits the complexity of the SQL statements that the server can handle, the recursion depth of stored procedures, and other memory-consuming actions. ”

    So the only reason it would be too small is if it was either set lower on purpose, or if there’s a lot of really memory-intensive usage of MySQL such that you care about Kb of RAM. (in that case make sure on <5.1 you're doing skip-bdb, and not allocating any space for an unused query_cache too!).

    If it's too large, you'll know because you can't handle the connections coming in.

    We've certainly had cases where we've seen that the default is too large and where the default is too small. "too large" we've seen on 2-3%, and "too small" is about 1% or less.

    But if the explicit setting is the same as the default, there shouldn't be a problem….unless the docs are wrong, in which case, please open a bug about that if there isn't a bug already.

    1. My info is from Monty who looked at the code. Based on that, I reckon the docs must be wrong. There is no static default, it’s dependent on the architecture. Well the exact calculation involves the size of an int, if I remember correct.

      Docs bug… right you are! http://bugs.mysql.com/bug.php?id=48550

Comments are closed.