4 Replies Latest reply on Oct 18, 2019 11:20 AM by Greg Brown

    AccessController performance in Wildfly

    Greg Brown Newbie

      Hi all,

       

      My team is in the process of upgrading our application from JBoss 4 to Wildfly 18 - yes, it's a big leap.  :-)  We have noticed an overall degradation in performance in Wildfly, and have recently been investigating the java.security.AccessController class as a potential bottleneck. In JBoss, privileged invocations (operations submitted to AccessController#doPrivileged()) run much more quickly (up to 50x faster) than they do in Wildfly. Since many of the JDK classes call doPrivileged(), our theory is that this may be contributing to the performance issues we are seeing.

       

      Does anyone have any suggestions on how we might set our Wildfly permissions to something more analogous to the JBoss configuration, to see if this resolves the problem?

       

      Thanks very much,

      Greg

        • 1. Re: AccessController performance in Wildfly
          Jaikiran Pai Master

          Is this with security manager enabled or disabled? Any screenshots/data that you can share which shows this 50x kind of change in performance, to help better narrow this down?

          • 2. Re: AccessController performance in Wildfly
            Greg Brown Newbie

            Security manager is not enabled. The following example can be used to reproduce the issue:

             

              @Test

              public void testAccessController() throws Exception

              {

                PrivilegedAction<Void> action = () -> {

                  System.out.print("");

                  return null;

                };

                long start = System.currentTimeMillis();

                for (int i = 0; i < 100000; i++) {

                  AccessController.doPrivileged(action);

                }

                long end = System.currentTimeMillis();

                log.info("Execution took {} millis", end - start);

              }

             

            When run in JBoss 4, each run takes ~24ms. In Wildfly 18, each run takes ~1300ms.

            • 3. Re: AccessController performance in Wildfly
              Greg Brown Newbie

              Update: When I calculate the time inside the action handler separately, it appears that the doPrivileged() plumbing accounts for about 20ms in both JBoss and Wildfly.

               

              In JBoss, the action itself only takes about 1ms total (for all 100K invocations). In Wildfly, the action accounts for the bulk of the 1,300ms. So the question actually may be - why does System.out.println() take so much longer in Wildfly? Maybe this is indicative of an I/O-related performance issue?

              • 4. Re: AccessController performance in Wildfly
                Greg Brown Newbie

                Here's a little more information. We have observed a repeatable performance issue with the XMLEncoder class as well. The following test takes about 2.6 on my machine:

                 

                public class TestApplication {

                    public static void runTest(PrintWriter writer) throws IOException {

                        final int COUNT = 50000;

                 

                        long start = System.currentTimeMillis();

                 

                        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

                 

                        try (XMLEncoder encoder = new XMLEncoder(byteArrayOutputStream)) {

                          for (int i = 0; i < COUNT; i++) {

                            encoder.writeObject(new Object[] {i, "abcdefghijklmnop"});

                          }

                        }

                 

                        String xml = new String(byteArrayOutputStream.toByteArray());

                 

                        try (StringReader reader = new StringReader(xml); XMLDecoder decoder = new XMLDecoder(new InputSource(reader))) {

                          for (int i = 0; i < COUNT; i++) {

                            decoder.readObject();

                          }

                        }

                 

                        long end = System.currentTimeMillis();

                 

                        writer.printf("Execution took %d millis\n", end - start);

                    }

                 

                    public static void main(String[] args) throws IOException {

                        PrintWriter writer = new PrintWriter(System.out);

                 

                        runTest(writer);

                 

                        writer.flush();

                    }

                }

                 

                However, when I run the same test in Wildfly (as a servlet), the test takes about 4.8 seconds:

                 

                @WebServlet(urlPatterns={"/*"}, loadOnStartup=1)

                public class TestServlet extends HttpServlet {

                    private static final long serialVersionUID = 0;

                 

                    @Override

                    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

                        TestApplication.runTest(response.getWriter());

                    }

                }