Spark: Memory leak with embedded Jetty server

Created on 18 Feb 2017  路  6Comments  路  Source: perwendel/spark

I have a small REST web service written in Spark. It's dead simple: it reads a remote DB and return JSON data to client. I run it using the default embedded Jetty server on Google Compute Engine:

java -jar file_name.jar

It works fine except for a serious memory leak issue. :( But in JVM dump, I cannot find anything suspicious. At least not related to my code. Is the embedded Jetty server the problem? Is anything suggestions or actions I can take to track down the issue?

Thank you so much,

Most helpful comment

Take a look at http://www.sql2o.org/docs/configuration/

I would try something like following.....

public class Main {
   public static void main(String[] args) {
     // setup once
      Sql2o sql2oForPing = new Sql2o(CONNECTION_URL, "user", "password");

      // reuse over and over
      get("/ping", (request, response) -> {
         try(Connection conn = sql2oForPing.open()) {
           return conn.createQuery("select count(*) from messages").executeScalar(Integer.class) > 0 ?
               "has data" : "no data";
         } catch (RuntimeException ex) {
           return "DB error:" + ex;
         }
      });
   }
}

All 6 comments

one possible way to track this down is to deploy this as a war to a stand alone jetty? that would at least eliminate the embedded jetty as a source

Same issue. Every request increasing to memory usage

? Is anything suggestions or actions I can take to track down the issue?

Strip away all non-offending code and post an example.

Sure, thanks! here is an example of my code:

public class Main {

   public static void main(String[] args) {
      get("/ping", (request, response) -> {
         Sql2o sql2oForPing = new Sql2o(CONNECTION_URL, "user", "password");
         try(Connection conn = sql2oForPing.open()) {
           return conn.createQuery("select count(*) from messages").executeScalar(Integer.class) > 0 ?
               "has data" : "no data";
         } catch (RuntimeException ex) {
           return "DB error:" + ex;
         }
      });
   }
}

BTW I am trying war file + Tomcat too. I will update the thread with result.

Take a look at http://www.sql2o.org/docs/configuration/

I would try something like following.....

public class Main {
   public static void main(String[] args) {
     // setup once
      Sql2o sql2oForPing = new Sql2o(CONNECTION_URL, "user", "password");

      // reuse over and over
      get("/ping", (request, response) -> {
         try(Connection conn = sql2oForPing.open()) {
           return conn.createQuery("select count(*) from messages").executeScalar(Integer.class) > 0 ?
               "has data" : "no data";
         } catch (RuntimeException ex) {
           return "DB error:" + ex;
         }
      });
   }
}

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Blok5 picture Blok5  路  5Comments

cnmade picture cnmade  路  6Comments

dmacvicar picture dmacvicar  路  5Comments

chibongho picture chibongho  路  4Comments

wowselim picture wowselim  路  5Comments