Repository navigation
Dropwizardifying - #1108
Dropwizardifying#1108michaz wants to merge 41 commits into
Conversation
|
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. |
|
(Except the bit-twiddling data-structures which make us fast.) :-) |
|
((But only the ones where we know this to be true.)) |
|
Cool & thanks!
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). |
|
Good - makes sense! |
|
|
||
| public class GraphHopperConfiguration extends Configuration { | ||
|
|
||
| public CmdArgs cmdArgs = new CmdArgs(); |
There was a problem hiding this comment.
No, not yet, because there's downstream code (in the other services in the other repos) which currently insists on replacing it.
| <artifactId>junit</artifactId> | ||
| <version>4.12</version> | ||
| <scope>test</scope> | ||
| </dependency> |
There was a problem hiding this comment.
We have this in the parent pom - is this really necessary in every submodule?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/"); |
There was a problem hiding this comment.
Could we use the route path for the api and a different endpoint for static assets instead?
There was a problem hiding this comment.
Hmmmm, but we want index.html at the root, right?
There was a problem hiding this comment.
Perhaps we can put a redirect to /webapp/index.html on / or something..
There was a problem hiding this comment.
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)); | |||
There was a problem hiding this comment.
Now I'm a bit unsure: why do we have a Configuration object with CmdArgs and here another instance?
There was a problem hiding this comment.
Same instance! Passed down over many levels. Way too complicated, but I can't simplify all at once. ,-)
| /** | ||
| * @author Peter Karich | ||
| */ | ||
| public class BaseServletTester { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
BTW: sometimes I run multiple tests in parallel and therefor I had this port start-trial-error loop in the BaseServletTester :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
wow - nice that this just goes away :)
|
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 (If at all.) |
|
This would be great.
This would be even better. Setting instances directly in the 'resources' should be possible once there are no servlets anymore I think. |
|
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. |
|
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 Dropwizard uses a config file first, and then patches that from system properties, like 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. ,-) |
Not very. But I would try to avoid the 'dw' property - is this possible somehow? Maybe just -Dgh.datareader.file=berlin-latest.osm.pbf ? |
|
Oh, I see we do the system property patching thing internally, anyway! So if we just advertise that way of passing command line parameters, |
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 |
That would be yet another method. |
|
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? ,-) |
Ah, will investigate, I thought this would work.. |
|
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:
|
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.
Oh, this is Logback, the format can be configured in the (Dropwizard/GraphHopper) config file.
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? |
Yes, by adding a healtheck. :-) They say they deliberately put that in to force people to look at healthchecks. |
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
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): |
|
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.ymlMy preferrence seems only possible via explicit parameters as Command: java -jar gh.jar server config.yml -datareader.file=some.pbfBut 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
For me, this works: Also with maven shade, as per current commit. Sure you didn't mistype? |
Signed-off-by: Michael Zilske <[email protected]>
|
Strange. It works now - thanks!
Works now without any change. |
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]>
|
@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. |
|
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. |
|
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. |
|
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
Later we should think about
|
Sure, but let's branch off another PR from there. Not revert anything here. Just making sure. |
|
Thanks for #1314 - will have a look and close this here |
New PR: #1314
Main conceptual changes (web module only):
Guice Modules are now wrapped by Dropwizard/Guice BundlesServlets 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.)