Skip to content

Dropwizardifying - #1108

Closed
michaz wants to merge 41 commits into
masterfrom
dropwizardify
Closed

michaz wants to merge 41 commits into
masterfrom
dropwizardify

Conversation

@michaz

@michaz michaz commented Jul 5, 2017 •

Copy link
Copy Markdown
Member

New PR: #1314

Main conceptual changes (web module only):

  • Guice Modules are now wrapped by Dropwizard/Guice Bundles
  • GraphHopper is wrapped by a GraphHopperService (something which can be started and stopped, managed by Dropwizard/Jetty), so that no heavy lifting is done at the time the Injector is created.
  • Servlets access things which are constructed by GraphHopper via a Provider, because now the Injector with the Servlets is not created by us (in "user space"), but by the framework, and that means that the things which GraphHopper creates aren't there yet (because GraphHopperService is not yet started), so we have to access them lazily. (This is because Servlets are always Singletons, created at startup, according to specs. The issue disappears for Dropwizard/Jersey Resource classes, which can simply be (by default, even?) created per-request, so issues of initialization order don't arise.)
  • The Configuration (Dropwizard concept) only wraps the CmdArgs for now. This is where to continue! I think half of GraphHopper's initialization/configuration/"manager" code will dissolve if we replace this by a hierarchy of configuration objects (which can include factories), which are automatically assembled from .yml (or anything else Jackson can parse), but can also be put together by hand, in Java.
  • The custom web integration test code is gone. Seems to work fine with the Dropwizard/Jersey client and test support classes, out of the box.
  • For the other web-services (map-matching, isochrones, etc.), no sub-classing or anything is required. You just compose Bundles.
  • TODO: Much of the custom Jetty configuration code is gone. Don't know how much of that is really missing/breaking anything. But maybe we could rather check if we can remove even more (IP filters etc.), as maybe that doesn't really belong in the web application but should be done by some outside proxy, or something.

@michaz

michaz commented Jul 5, 2017 •

Copy link
Copy Markdown
Member Author

Next steps: Reap the returns from using a framework, by simplifying, simplifying, simplifying, and using standard-based mechanisms for configuration, serialization, web-serving, and everything which isn't routing itself. Ideally, there should at one point be almost no code left which does not directly talk about roads or vehicles or cost or distance etc.

@michaz

michaz commented Jul 5, 2017 •

Copy link
Copy Markdown
Member Author

(Except the bit-twiddling data-structures which make us fast.) :-)

@michaz

michaz commented Jul 5, 2017

Copy link
Copy Markdown
Member Author

((But only the ones where we know this to be true.))

@karussell

Copy link
Copy Markdown
Member

Cool & thanks!

The Configuration (Dropwizard concept) only wraps the CmdArgs for now. This is where to continue!

My preferred way here is to go via a custom json (is this possible)? Because having a yml for service config and another json for vehicle profiles seems suboptimal to me (especially if different formats).

@michaz

michaz commented Jul 5, 2017 •

Copy link
Copy Markdown
Member Author

My preferred way here is to go via a custom json (is this possible)? Because having a yml for service config and another json for vehicle profiles seems suboptimal to me (especially if different formats).

Not sure, but to me it looks like in the end it will take anything Jackson can parse (including JSON, Yaml and who knows what else).

@karussell

Copy link
Copy Markdown
Member

Good - makes sense!


public class GraphHopperConfiguration extends Configuration {

public CmdArgs cmdArgs = new CmdArgs();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better make it final?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not yet, because there's downstream code (in the other services in the other repos) which currently insists on replacing it.

Comment thread tools/pom.xml
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this in the parent pom - is this really necessary in every submodule?

@michaz michaz Aug 22, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I stumbled over this because dropwizard has its "dropwizard-testing", which includes a junit version.

Why do we have dependencies in the parent pom? Do they belong there? Parents often do "dependency management", where they say to children "if you need dependency A, then use version a.b" (to resolve conflicts with siblings). But ultimately only the modules by themselves can know what dependencies they have.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do they belong there?

I do not know for sure. I just didn't thought of a case where we won't need junit and wanted to reduce code a bit.

where they say to children "if you need dependency A, then use version a.b" (to resolve conflicts with siblings).

ok

// and the API root cannot _both_ be mapped to "/".
// We don't use Jersey services yet (instead: pure Servlets),
// but once we do, we have to think of something.
serverFactory.setJerseyRootPath("/api/");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the route path for the api and a different endpoint for static assets instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, but we want index.html at the root, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can put a redirect to /webapp/index.html on / or something..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I would prefer to break the demo UI instead of breaking any API out there, I'm more for a change there like having /demo or similar.

@@ -62,110 +42,39 @@ public GraphHopperModule(CmdArgs args) {
protected void configure() {
install(new CmdArgsModule(args));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm a bit unsure: why do we have a Configuration object with CmdArgs and here another instance?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same instance! Passed down over many levels. Way too complicated, but I can't simplify all at once. ,-)

/**
* @author Peter Karich
*/
public class BaseServletTester {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that we can get rid of it :) !

@Test
public void testBasicQuery() throws Exception {
JsonNode json = query("point=42.554851,1.536198&point=42.510071,1.548128", 200);
JsonNode json = app.client().target("http://localhost:8080/route?point=42.554851,1.536198&point=42.510071,1.548128").request().buildGet().invoke().readEntity(JsonNode.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we try to use a test server port which does not collide when running the normal thing? Because often I have a GH server running and still want to run the tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: sometimes I run multiple tests in parallel and therefor I had this port start-trial-error loop in the BaseServletTester :)

@michaz michaz Jul 5, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeeeeeeah, also it looked a bit like it was starting many servers but shutting down only one. (Not 100% sure..)

I see the point, but please also see the transparency of just writing down the port number which is tested. And of testing the real server application with its real default port number / real way of configuring its port number.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multiple port approach probably was a bit too much, but we need test and production separation for multiple reasons. As this is easily achievable via a fixed test port and also transparent I do not see a big pain here. Furthermore the default production port should be the old 8989.

@michaz michaz Jul 24, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore the default production port should be the old 8989.

Okay, that would go into the default config file, which we should provide. (Probably migrate the example properties file which we have now.)

(Config file is not optional in DW, there is no such thing as an empty default config.)

@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we can easily remove this. In production it is very important to have async logging as otherwise routing requests could be delayed if disc is busy. This is especially true under high load and when we fetch GBs of new road network data.

@michaz michaz Jul 24, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropwizard uses Logback, not log4j -- I hope it has reasonable defaults (I should think so). Otherwise, the configuration goes in the main dropwizard config file. This file here was in a test directory anyway -- can't do anything in production.

*
* @author Peter Karich
*/
public class ChangeGraphServlet extends GHBaseServlet {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow - nice that this just goes away :)

@michaz

michaz commented Jul 6, 2017 •

Copy link
Copy Markdown
Member Author

Currently trying to get rid of Guice, because I already found what I think is a bug in the third-party Dropwizard-Guice-integration.

Dropwizard already contains a full javax.inject implementation, so we should rather use that.

(If at all.)

@karussell

Copy link
Copy Markdown
Member

This would be great.

(If at all.)

This would be even better. Setting instances directly in the 'resources' should be possible once there are no servlets anymore I think.

@michaz

michaz commented Jul 7, 2017

Copy link
Copy Markdown
Member Author

Let's let this rest for a while, I'll use and test it for developing my next few features and see how it behaves.

@michaz

michaz commented Jul 24, 2017 •

Copy link
Copy Markdown
Member Author

Okay, the YAML vs. JSON thing is not an issue, and the reading of our property file is also fine.

But our command line options are a problem, like datareader.file=berlin-latest.osm.pbf.

Dropwizard uses a config file first, and then patches that from system properties, like -Ddw.graphhopper.datareader.file=berlin-latest.osm.pbf (with the dw prefix hardcoded).

How important is it to be exactly backwards-compatible to how we currently call the JAR?

I can write any number of custom entry points, of course, but.. hey, this is a framework. ,-)

@karussell

Copy link
Copy Markdown
Member

How important is it to be exactly backwards-compatible to how we currently call the JAR?

Not very. But I would try to avoid the 'dw' property - is this possible somehow? Maybe just -Dgh.datareader.file=berlin-latest.osm.pbf ?

@michaz

michaz commented Jul 24, 2017

Copy link
Copy Markdown
Member Author

Oh, I see we do the system property patching thing internally, anyway! So if we just advertise that way of passing command line parameters, -Dgraphhopper.datareader.file=berlin-latest.osm.pbf? It already works that way, right?

@karussell

Copy link
Copy Markdown
Member

It already works that way, right?

Hmmh, yes, it should. We could introduce some abbreviation so that only "-Dgh." needs to be added and moved from program to JVM system options

@michaz

michaz commented Jul 24, 2017

Copy link
Copy Markdown
Member Author

We could introduce some abbreviation so that only "-Dgh." needs to be added and moved from program to JVM system options

That would be yet another method. graphhopper exists and seems to work. Just tried it.

@michaz

michaz commented Aug 7, 2017

Copy link
Copy Markdown
Member Author

Okay, I would call this almost finished, but it needs plenty of testing how it behaves on our servers. Maybe you can give it a try on a test machine at some point?

Oh, by the way, JSONP is gone right now. We need that, right? ,-)

@michaz

michaz commented Jan 26, 2018

Copy link
Copy Markdown
Member Author

Now I cannot make the command line arguments ala -Dgraphhopper.datareader.file working, it always says "You need to specify an OSM file." and I have to use the config file, which is suboptimal for scripting.

Ah, will investigate, I thought this would work..

@karussell

karussell commented Jan 31, 2018 •

Copy link
Copy Markdown
Member

There is also a possibility to specify commands after the jar file: http://www.dropwizard.io/0.9.1/docs/manual/core.html#man-core-commands

Some notes/questions:

  • for every request there seems to be an additional log line ala <requested_IP> - - [31/Jan/2018:06:57:01 +0000] "GET /route?point=37.438541 and not just INFO .. or ERROR ..
  • And should we keep the current logging format or switch to the standard dropwizard? I slightly prefer to keep it if not too much effort - are there some advantages we would get for "standard dropwizard"?
  • also there is always a 0 at the end of each log line. Is this the time it takes per request and is a rounded integer?
  • Something is wrong. I cannot get the system to accept more than 10 queries per second. Will investigate.
  • can we avoid the healthcheck warning at start up?
  • should we use endpoint /maps instead of /webapp for UI demo?
  • the graphhopper banner for CLI is not fully printed, one part of the second P is missing somehow
  • Do you get the same problem regarding the configuration parsing and were able to fix it via maven shade or am I doing it wrong?
  • It looks that we are blocking IPs for the application properly but not for admin. So either we should block it for both or disable the admin service to avoid security problems for people using this feature

@michaz

michaz commented Feb 2, 2018 •

Copy link
Copy Markdown
Member Author

for every request there seems to be an additional log line ala <requested_IP> - - [31/Jan/2018:06:57:01 +0000] "GET /route?point=37.438541 and not just INFO .. or ERROR ..

Yes. From what I've heard, it is a standard "access log" format which also things like NGINX produce, which deliberately looks different from the rest of the application log, and which is analysed by many standard tools. I'm sure it can be switched off. Though I'd rather suggest to leave it on and remove our own (similar) line.

And should we keep the current logging format or switch to the standard dropwizard? I slightly prefer to keep it if not too much effort - are there some advantages we would get for "standard dropwizard"?

Oh, this is Logback, the format can be configured in the (Dropwizard/GraphHopper) config file.

It looks that we are blocking IPs for the application properly but not for admin. So either we should block it for both or disable the admin service to avoid security problems for people using this feature

Here I'd strongly suggest to either turn off admin service, or do nothing. I think we should remove IP filtering from the open source version. I have the rather strong opinion that a specialised web service which uses a framework should just leave the defaults of that framework like they are. Because this is the least surprise for a user who just Googles "Dropwizard" to see how it works.

I think the reasonable expectation is that a webservice is just a webservice, and that things like logging (somewhere else than to stdout), security, etc. are managed by proxies or containers, or must be explicitly put in by the user. But you know our users better. :-)

I know there's a concern like backwards compatibility, but if I would start from scratch, I would leave everything at the defaults, including port number etc.

Maybe switching off the admin port in the default config is a good compromise?

@michaz

michaz commented Feb 2, 2018 •

Copy link
Copy Markdown
Member Author

can we avoid the healthcheck warning at start up?

Yes, by adding a healtheck. :-) They say they deliberately put that in to force people to look at healthchecks.

@michaz

michaz commented Feb 2, 2018 •

Copy link
Copy Markdown
Member Author

Something is wrong. I cannot get the system to accept more than 10 queries per second. Will investigate.

Now that is irritating. I'd be happy to learn more.. (Before looking into the rest. :-) )

# Conflicts:
#	core/src/main/java/com/graphhopper/Trip.java
#	core/src/main/java/com/graphhopper/util/shapes/GHPoint.java
#	reader-gtfs/src/main/java/com/graphhopper/reader/gtfs/TripFromLabel.java
@karussell

karussell commented Feb 13, 2018 •

Copy link
Copy Markdown
Member

Something is wrong. I cannot get the system to accept more than 10 queries per second. Will investigate.

This looks much better now :). I think this is a measurement bug when there are errors. Now I was able to reduce the errors for the test instance and still use a realistic scenario and I'm getting 650-950 requests/sec for 10 workers (not that bad as we skips routes <100km)

The interesting thing is that dropwizard seems to better handle more workers. For workers>5 the throughput is often measurable better and much less differences there between two identical runs ("more predictable"). To avoid log and disc related slow down I piped the logs into /dev/null for both but maybe there are other problems in the measurement procedure or differences in the jetty version or config.

For future reference: I'm using world wide car data only, with 30GB RAM (graph is 28gb) and real world logs from production (mostly with CH) and execute the following on a different server very close to the GH server (ping <0.25ms):

./graphhopper.sh torture logfile=~/some.logs.gz workers=10 'baseurl=http://host:8989/route?' maxqueries=30000 timeout=1000

@karussell

Copy link
Copy Markdown
Member

Also found how to specify parameters via command line which is a bit ugly due to the long prefix "-Ddw.graphhopper." and because escaping the dot is required:

java -Ddw.graphhopper.datareader\\.file=some.pbf -jar gh.jar server config.yml

My preferrence seems only possible via explicit parameters as Command:

java -jar gh.jar server config.yml -datareader.file=some.pbf

But then we would need to duplicate configuration information in the configuration object and in the command object.

# Conflicts:
#	web/src/main/java/com/graphhopper/http/PtModule.java
@michaz

michaz commented Feb 18, 2018

Copy link
Copy Markdown
Member Author

Now I cannot make the command line arguments ala -Dgraphhopper.datareader.file working, it always says "You need to specify an OSM file." and I have to use the config file, which is suboptimal for scripting.

For me, this works:

java -jar -Dgraphhopper.datareader.file=wurst web/target/graphhopper-web-0.10-SNAPSHOT.jar server config-example.yml

Also with maven shade, as per current commit. Sure you didn't mistype?

@karussell

Copy link
Copy Markdown
Member

Strange. It works now - thanks!

Also with maven shade, as per current commit. Sure you didn't mistype?

Works now without any change.

michaz added 6 commits March 2, 2018 11:11
Signed-off-by: Michael Zilske <[email protected]>
(cherry picked from commit 2487581)
Signed-off-by: Michael Zilske <[email protected]>
Signed-off-by: Michael Zilske <[email protected]>
(cherry picked from commit 7e81de3)
Signed-off-by: Michael Zilske <[email protected]>
@karussell

Copy link
Copy Markdown
Member

@michaz it would be better to create a new branch for new features here. I know we are very late to merge this but new features and new dependencies should not be added as they could make previous testing obsolete. Also I would like to discuss this first, e.g. why adding this to the core and why not e.g. hibernate validator etc.

@michaz

michaz commented Mar 5, 2018

Copy link
Copy Markdown
Member Author

Ok sure. Thing is, I'm actually using this stuff for my test instance, which means I'm already kind-of maintaining three different states.. Not sure if I can handle a fourth one. :-/ But I see the point.

@karussell

Copy link
Copy Markdown
Member

Oh, why three states :D ? Next thing after full release is this, so it should not take long or I can use the commit at shade plugin.

@michaz

michaz commented Mar 5, 2018

Copy link
Copy Markdown
Member Author

Oh, why three states :D ?

master, dropwizardify, trimet. I currently do a merge-chain every time I commit a new domain-level feature. ,-) Not catastrophic, but not optimal either.

@karussell

Copy link
Copy Markdown
Member

I'm sure it can be switched off. Though I'd rather suggest to leave it on and remove our own (similar) line.

The problem is that we need some more information like used algorithm etc. But yes, if we can use some kind of standard this would be an additional improvement.

So now that we have 0.10 released I would like to merge this and before merging we need to fix only some minors

  • switch back to commit 72ef9c1
  • adapt graphhopper.sh (I'll do this. We then take arguments and forward them directly to the java app but we need a tiny wrapper to download the pbfs, potentially install maven and use some good defaults)
  • additionally to -Dgraphhopper allow -Dgh (or only allow the latter?)
  • avoid double logging, see above
  • turn off admin service in config by default for security reasons
  • adapt docs to document new config options or provide a backward compatible way
  • add healthcheck to avoid warning at start up
  • use endpoint /maps instead of /webapp for UI demo
  • the graphhopper banner for CLI is not fully printed, one part of the second P is missing

Later we should think about

  • a converter from old properties to new json/yml format?
  • remove IPFilter but we should avoid being a target like memcache ;)

@michaz

michaz commented Mar 10, 2018

Copy link
Copy Markdown
Member Author

switch back to commit

Sure, but let's branch off another PR from there. Not revert anything here. Just making sure.

@karussell

Copy link
Copy Markdown
Member

Thanks for #1314 - will have a look and close this here

@karussell karussell closed this Mar 18, 2018
@michaz
michaz deleted the dropwizardify branch April 22, 2020 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants