Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest API #3

Merged
merged 5 commits into from
Nov 11, 2016
Merged

Rest API #3

merged 5 commits into from
Nov 11, 2016

Conversation

giulio-zhou
Copy link
Contributor

  • parse uid, input (vector) and label from predict and update requests
  • attaches boost continuation onto future returned from call to qp.predict and qp.update, which then fulfills the http request
  • included server_http.hpp file directly
    TODO: put this in an interface library

* parse uid, input (vector<double>) and label from predict and update requests
* attaches boost continuation onto future returned from call to
    qp.predict and qp.update, which then fulfills the http request
* included server_http.hpp file directly
    TODO: put this in an interface library
Copy link
Contributor

@dcrankshaw dcrankshaw left a comment

Choose a reason for hiding this comment

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

This looks good!

One key part of the REST API is the ability to configure new endpoints at runtime. For example, someone in devops should be able to deploy a Clipper cluster (potentially with no REST endpoints). A data scientist who wants to add a predictive recommendation application should then be able to add a new REST endpoint to the running Clipper instance without having to write any code or even restart the service.

That shouldn't all happen in this initial implementation, but let's make the implementation general enough to support this going forward. Here are the things that need to happen on a per-endpoint basis (ideally at runtime):

  1. Listen at endpoint (http://clipper:1337/ads, http://clipper:1337/recs, etc).
  2. Parse input
  3. Specify selection policy
  4. Generate query (get list of candidate models, set SLO.

TODO for this PR:

  • Figure out how to support multiple named endpoints with the same request handler without explicitly hardcoding each endpoint.
  • Create a generic add_application() function to create each endpoint that takes as arguments those 4 items above. For now this doesn't need to be called at runtime and can take lambdas or something to parse the input and specify the candidate models.

@@ -4,7 +4,7 @@
#include <utility>
#include <vector>

#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there's a canonical place to define this once, so that we don't have to rely on developers setting this every time they include boost/thread.

Choose a reason for hiding this comment

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

yes, when using Makefile projects I was just passing the -DBOOST_THREAD_VERSION=X preprocessing flag.

Choose a reason for hiding this comment

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

something like this :
https://cmake.org/cmake/help/v3.2/command/add_definitions.html
add_definitions( -DBOOST_THREAD_VERSION=4)

@@ -4,7 +4,7 @@
#include <utility>
#include <vector>

#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_VERSION 4
#include <boost/thread.hpp>
#include <boost/thread/future.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

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

I was reading about how to include boost thread this weekend, and it looks like we don't need both include lines. You can remove #include <boost/thread/future.hpp> because boost/thread.hpp includes it.

See http://www.boost.org/doc/libs/1_62_0/doc/html/thread.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, turns out it's not necessary. Will remove on the next update to this PR.

@@ -0,0 +1,438 @@
#ifndef SERVER_HTTP_HPP
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file from Simple-Web-Server? We should attribute the source and include its license in a comment at the top of the file.

We should also add it to src/libs and expose it as an INTERFACE library in cmake using add_library()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, definitely. Will try to get that working on the next update.

#include "server_http.hpp"

using namespace std;
using namespace clipper;
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't include all members of a namespace (see https://google.github.io/styleguide/cppguide.html#Namespaces). You can using ::clipper::QueryProcessor; instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, I'd end up with each of these using statements.
using clipper::DoubleVector;
using clipper::FeedbackAck;
using clipper::Input;
using clipper::Output;
using clipper::QueryProcessor;
using clipper::Response;
which seems a bit excessive. Any thoughts?

using namespace std;
using namespace clipper;
using namespace boost::property_tree;
typedef SimpleWeb::Server<SimpleWeb::HTTP> HttpServer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use alias declarations not typedef. So this should be using HttpServer = SimpleWeb::Server<SimpleWeb::HTTP>;

See Item 9 in Effective Modern C++ for an explanation (I can send you a pdf of it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix. Also, that would be useful. Thanks!

}

class RequestHandler {
HttpServer server;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this private? Let's have an explicit private section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

@giulio-zhou
Copy link
Contributor Author

Updated the request handler with an add_endpoint function (currently defines the entire handling function). Later on, I'll break it up into the multiple functions corresponding to the steps you described.

@dcrankshaw
Copy link
Contributor

@giulio-zhou Is this ready for a final review?

@giulio-zhou
Copy link
Contributor Author

Not quite yet, but almost ready. Still need to add server_http.hpp as an INTERFACE library. Let me know if you have any other thoughts on the current state of the code. For now, it may be sufficient to just have the add_endpoint method take in a lambda that does everything.

@dcrankshaw
Copy link
Contributor

Cool. Let me know when it's ready. @Corey-Zumar and I spent some time figuring out how to add new third-party header-only libraries as interface libraries the other day. Check out the example for ZeroMQ to get started.

@giulio-zhou
Copy link
Contributor Author

Included server_http as a library, ready for review.

@giulio-zhou giulio-zhou changed the title Rest API (first draft, DO NOT MERGE) Rest API Nov 10, 2016
@dcrankshaw
Copy link
Contributor

LGTM. Can you add a short README.md in src/frontends that shows an example predict query and we'll get this merged?

@giulio-zhou
Copy link
Contributor Author

Just wanted to clarify something before proceeding. For the readme, are you thinking of, say, how to formulate a prediction query from a Python client? Or more like the steps I'd need to take to define a different endpoint?

@dcrankshaw
Copy link
Contributor

How to issue a query with curl. Say what the endpoint is (http://localhost:1337/predict), that it should be a post message, and what the format of the body should be.

@giulio-zhou
Copy link
Contributor Author

Ok, sounds good. I'll do that later tonight.

@dcrankshaw
Copy link
Contributor

For some reason @atumanov's comments aren't making it into the thread. To echo them:
something like this :
https://cmake.org/cmake/help/v3.2/command/add_definitions.html
add_definitions( -DBOOST_THREAD_VERSION=4)

@giulio-zhou
Copy link
Contributor Author

Added README and fixed up boost thread version includes.

@dcrankshaw dcrankshaw merged commit 4c10726 into develop Nov 11, 2016
@dcrankshaw
Copy link
Contributor

Merged!

dcrankshaw referenced this pull request in dcrankshaw/clipper May 10, 2017
# This is the 1st commit message:
started work on spark container

# This is the commit message #2:

rearranged files in maven packages

# This is the commit message #3:

training example works

# This is the commit message #4:

Copies jar to known location

# This is the commit message #5:

loading container class from jar not working yet

# This is the commit message #6:

got jar loading working
dcrankshaw referenced this pull request in dcrankshaw/clipper May 17, 2017
# This is the 1st commit message:
started work on spark container

# This is the commit message #2:

rearranged files in maven packages

# This is the commit message #3:

training example works

# This is the commit message #4:

Copies jar to known location

# This is the commit message #5:

loading container class from jar not working yet

# This is the commit message #6:

got jar loading working
dcrankshaw referenced this pull request in dcrankshaw/clipper May 17, 2017
# This is the 1st commit message:
started work on spark container

# This is the commit message #2:

rearranged files in maven packages

# This is the commit message #3:

training example works

# This is the commit message #4:

Copies jar to known location

# This is the commit message #5:

loading container class from jar not working yet

# This is the commit message #6:

got jar loading working
Corey-Zumar pushed a commit that referenced this pull request May 18, 2017
…o repl support (#133)

* # This is a combination of 6 commits.
# This is the 1st commit message:
started work on spark container

# This is the commit message #2:

rearranged files in maven packages

# This is the commit message #3:

training example works

# This is the commit message #4:

Copies jar to known location

# This is the commit message #5:

loading container class from jar not working yet

# This is the commit message #6:

got jar loading working

* initial work on incorporating REPL classes.

some cleanup and re-org. untested

basic example working

loading classes defined in REPL still doesn't work

started java reorg

Reorganized code. Everything compiles

Finished implementation. Now need docker container and lots of debugging.

start work on docker container

fixed bug in docker file

Fixed some bugs

Clipper local deploy seems to be working

Fixed some bugs

Deploy is working but there's something wrong with the container

Remote deploy is working!

Spark scala deploy is working both locally and remotely

Formatting

started to add tests

* mostly done with rebase

* rebase complete with existing tests passing

* Format code

* Fix typo

* added unit tests

* addressed review comments

* add some notes on how to run Spark example

* fixed typo in comment
@dcrankshaw dcrankshaw deleted the rest-api branch June 23, 2017 20:29
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.

3 participants