Max File Descriptors Setting

I am trying to make a load test on an API with a lot of concurrent requests. you can see the test below, However, it had troubles due to max file descriptors by OS, I increased that level and passed that problem. I verified that by running CheckOpenFS with -XX:-MaxFDLimit, However, maven does not recognize it with MAVEN_OPTS or any other setting and it does not recognize JVM flag or maybe it maven recognizes it but Gatling plugin somehow omits.

Can you help me to run help running gatling:test running with OS default max descriptors

CheckOpenFS:

import com.sun.management.UnixOperatingSystemMXBean;
import java.lang.management.ManagementFactory;

public class CheckOpenFS {

    public static void main(String[] args) {
        final UnixOperatingSystemMXBean osMBean =
                (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        System.out.println("opendfs: " + osMBean.getOpenFileDescriptorCount());
        System.out.println("maxfds:  " + osMBean.getMaxFileDescriptorCount());
    }

}


CheckOpenFS Console output:

/Users/mustafayildirim/.sdkman/candidates/java/21.ea.28-open/bin/java -XX:-MaxFDLimit -javaagent:/Users/mustafayildirim/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.9161.38/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=61416:/Users/mustafayildirim/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.9161.38/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /Users/mustafayildirim/IdeaProjects/untitled/out/production/hackerearth CheckOpenFS
opendfs: 8
maxfds:  64000

Process finished with exit code 0

Maven Gatling test class

package computerdatabase

import io.gatling.javaapi.core.*
import io.gatling.javaapi.http.*
import io.gatling.javaapi.core.CoreDsl.*
import io.gatling.javaapi.http.HttpDsl.*
import java.time.Duration

import java.util.concurrent.ThreadLocalRandom
import kotlin.random.Random
import com.sun.management.UnixOperatingSystemMXBean
import java.lang.management.ManagementFactory

/**
 * This sample is based on our official tutorials:
 *
 * - [Gatling quickstart tutorial](https://gatling.io/docs/gatling/tutorials/quickstart)
 * - [Gatling advanced tutorial](https://gatling.io/docs/gatling/tutorials/advanced)
 */

class ComputerDatabaseSimulation : Simulation() {



    val httpProtocol =
        http
            // Here is the root for all relative URLs
            .baseUrl("http://localhost:9595")
            .enableHttp2()

    // A scenario is a chain of requests and pauses
    val scn =
        scenario("Scenario Name")
            .exec(
                http("request_1").get("/multiply")
                    .queryParam("num1", Random.nextInt())
                    .queryParam("num2", Random.nextInt())
            )

    init {
            val osMBean = ManagementFactory.getOperatingSystemMXBean() as UnixOperatingSystemMXBean
            println("opendfs: ${osMBean.openFileDescriptorCount}")
            println("maxfds:  ${osMBean.maxFileDescriptorCount}")
        setUp(
            scn.injectOpen(
                stressPeakUsers(1).during(30)
            ).protocols(httpProtocol)
        )
    }
}

ComputerDatabaseSimulation Console output:

opendfs: 169
maxfds:  10240
Simulation computerdatabase.ComputerDatabaseSimulation started...

OS tuning is in the documentation and an absolute must:

The top file descriptor limit on GNU/Linux is ~65K. Run only Gatling and associated tools on your load injector. The Gatling Enterprise boxes will be pre-tuned. Whoever at Gatling Corp suggested the tuning knows their stuff because I don’t even understand some of the settings and must have a system administrator background. Explanations may be nice. TODO: Provide kernel tuning explanations and submit a PR.

There is nothing on filesystem paramaters, but distros use different filesystems. Ext4 was the most common Linux filesystem, but some distros will be using btrfs now.

Maybe (and feel free to rebuke me) increase inode cache, the readahead buffer size, enable delayed allocation and optimise the journaling mode.

1 Like

these are my settings

> ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8176
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       2666
-n: file descriptors                64000
> sudo cat /Library/LaunchDaemons/limit.maxfiles.plist
Password:
<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
          "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>limit.maxfiles</string>
      <key>ProgramArguments</key>
      <array>
        <string>launchctl</string>
        <string>limit</string>
        <string>maxfiles</string>
        <string>64000</string>
        <string>200000</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
      <key>ServiceIPC</key>
      <false/>
    </dict>
  </plist>
>

And about last lines of your message- I don’t know how to tune them(inode cache etc.) but I will check. I made some progress by tuning client(gatling) and server(my application) by changing java args(-XX:-MaxFDLimit ) but the only change is my error, now I get this


At least, something new to investigate :laughing:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.