Skip to content

Add JSON API to server #1868

Closed
Closed

Description

@mlucy

@nviennot's pull requests inspired me to look at ruby driver performance a bit more, and I don't think we can really make the driver fast until we move off of it's protobuf library.

I've looked, and there doesn't seem to be a better one available. I think the best option right now would be to add a JSON API to the server. (This will also allow third-party driver writers without access to fast protobuf libraries to benefit.)

Putting in subsequent and tagging as lts.

Activity

  1. ghost assigned on Jan 16, 2014
  2. mlucy commented on Jan 16, 2014

    @mlucy
    MemberAuthor

    Also, as part of this we may finally want to move off of cJSON on the server.

  3. mlucy commented on Jan 24, 2014

    @mlucy
    MemberAuthor

    OH! Also, if we have a JSON representation for ReQL:

    • ReQL will be homoiconic for the LTS release. This way we won't have to hide our faces in shame when we go to PL conferences.
    • We will be able to store functions (and queries, actually) in tables. Then we implement r.eval and make @mglukhovsky buy us a cake.
  4. wojons commented on Jan 30, 2014

    @wojons
    Contributor

    I think if its in before or for the LTS would be a big thing. If it comes after LTS people are going to build there apps maybe build more community drivers that would follow protobufs and then be at a disadvantage. When you say json api do you mean how the json will be formed and it will be the same underline protocol or both things will change.

  5. mlucy commented on Jan 30, 2014

    @mlucy
    MemberAuthor

    I mean "you won't need protobufs to talk to the server any more". The format of the JSON document you send will probably map pretty closely to the current format of the protobuf you send. (I think we may also support protobufs for a few versions as a deprecated feature so that people's drivers don't immediately break.)

  6. wojons commented on Jan 30, 2014

    @wojons
    Contributor

    I know this sounds really dumb but i know some languages have there own serialization format which can be faster for them then it is to use things like json. I think php just calles it serialization and python has pickle. I guess it would be a lot to support all of them but may be much faster in some languages then there existing json implantation.

  7. orthecreedence commented on Feb 13, 2014

    @orthecreedence

    I think we may also support protobufs for a few versions as a deprecated feature so that people's drivers don't immediately break

    Question: are you talking about completely replacing the protobuf API on the server with a JSON API, or are you referring to the Ruby drivers specifically here?

  8. mlucy commented on Feb 13, 2014

    @mlucy
    MemberAuthor

    @orthecreedence -- I think the current plan is for the server to support both a protobuf API and a JSON API for a few versions, with the protobuf API marked as deprecated. The protobuf API would then be removed at some point in the future.

  9. orthecreedence commented on Feb 13, 2014

    @orthecreedence

    Got it, just checking. Thanks!

  10. colprog commented on Feb 13, 2014

    @colprog

    The high CPU usage problem of protobuf serialization/deserialization is really a problem for my node.js app. I've recently came across this: https://github.com/kentonv/capnproto. have you guys considered using this to replace protobuf?

  11. coffeemug commented on Feb 13, 2014

    @coffeemug
    Contributor

    To be honest protobufs made us a bit jaded. It's a well-supported library from Google that's broadly adopted, and it sucks. Before we switch to another library we'd have to test the living hell out of it, which is a lot effort. Alternatively we can just pick json which we know works, is supported everywhere, and is very fast. That seems like a path of least resistance that we know will work.

  12. wojons commented on Feb 13, 2014

    @wojons
    Contributor

    @coffeemug I totally agree but think its better to try other things before going with json also should still test the living hell out of json. I think thrift is pretty good. And if you want messaging have heard great things about zeromq.

  13. coffeemug commented on Feb 13, 2014

    @coffeemug
    Contributor

    @wojons 👍

  14. wojons commented on Feb 13, 2014

    @wojons
    Contributor

    Regardless I love rethink and will test any random branch you guys need some anayalitics engine to test.

  15. neumino commented on Feb 13, 2014

    @neumino
    Member
  16. 27 remaining items

  17. jcspencer commented on Mar 29, 2014

    @jcspencer

    The only question I have about this change is will authentication change at all? As HTTP allows the use of many authentication specs.

  18. neumino commented on Mar 29, 2014

    @neumino
    Member

    @JamesS237 -- What @mlucy is proposing here is to remove protobuf, not to have an http server that get JSON and execute queries.
    So instead of sending the serialized version of a JSON object, we just send the raw JSON object.

    @mlucy would be able to tell you more about that though.

  19. srh commented on Mar 29, 2014

    @srh
    Contributor

    No. Unless I'm missing something about the data explorer. The JSON API does not use HTTP.

  20. jcspencer commented on Mar 29, 2014

    @jcspencer

    Oh, okay.

  21. coffeemug commented on Apr 7, 2014

    @coffeemug
    Contributor

    This is going to be part of the first sprint. @mlucy agreed to get this merged by the end of the week.

  22. coffeemug commented on Apr 7, 2014

    @coffeemug
    Contributor

    Also talked to @Tryneus -- he agreed to get an implementation of this for the drivers into code review by the end of the week.

  23. mlucy commented on Apr 7, 2014

    @mlucy
    MemberAuthor

    This (and the Ruby driver implementation) are in next. I'm not convinced there aren't bugs, but I'm hoping developer use will help catch them. I'm going to open new issues for the Python and JS implementations.

  24. wojons commented on Apr 7, 2014

    @wojons
    Contributor

    @danielmewes

    not sure if ur planning on doing the php driver for this one or hoping somoen else wll do it but if there any docs for how to do this i can try to get this setup and going? and if someone lets me know how to compile for this one i am willing to run it on my dev stack.

  25. danielmewes commented on Apr 7, 2014

    @danielmewes
    Member

    @wojons I would definitely do it, but feel free to give it a try yourself if you don't want to wait so long. It should be rather easy in case of the PHP driver, because it already uses an abstract representation that is converted to a protocol buffer only before sending the query over the wire. @mlucy: Are you planning to write documentation for the protocol?

  26. neumino commented on Apr 7, 2014

    @neumino
    Member

    :+1 for some docs -- If you could comment here, it would be pretty cool -- rethinkdb/docs#24

  27. mlucy commented on Apr 7, 2014

    @mlucy
    MemberAuthor

    Opened an issue for that: #2225 . I'll try to get to it soon.

    A brief summary for anyone who wants to get started:

    • We still use the protobuf constants, for efficiency.
    • We use arrays to represent function calls, the the second argument being the args and the third (optional) being the optargs.
    • You use the MAKE_ARRAY function for a literal array.

    So:

    r.table('test').merge({a: [1,2,3]})
    =>
    [MERGE,
     [TABLE, "test"]
     {a: [MAKE_ARRAY, [1, 2, 3]]}]
    

    The easiest way to do this right now would probably be to use the Ruby driver to generate protobufs, and put a printf either on the server (in json_shim.cc) or in the driver (in net.rb in dispatch) to see what JSON it generates.

  28. AtnNn commented on Apr 7, 2014

    @AtnNn
    Member

    @mlucy The ruby driver has to_pb. Can you also add a working to_json?

  29. mlucy commented on Apr 7, 2014

    @mlucy
    MemberAuthor
    irb(main):004:0> r.table('test').merge({a: [1,2,3]}).to_json
    "[35,[[15,[\"test\"]],{\"a\":[2,[1,2,3]]}]]"                
  30. mlucy commented on Apr 7, 2014

    @mlucy
    MemberAuthor

    So, my example was actually incorrect; I forgot to put the arguments into an array together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions