@Matt: thanks for your summary.
> The current 2.0 suggests handling batch as an array of request and
> that it should return an array of responses. This of course had
> generated questions like:
> * how to handle notifications
Notifications should be omitted IMHO in the response; The only
question is: What should happen if the multicall only contains
notifications?
Should (a) an empty array be returned, or (b) no response sent at all?
> * order in which to process
> * order in which to return
I think we will have two different kinds of "multicall":
- A very simple multicall, which cannot be configured, and is mainly
intended for reducing overhead. This is the thing called "Batch"
in the JSON-RPC 2.0 draft.
- A more complex multicall, which can be configured.
This could be done by an extension, where the behaviour could be
configured with some parameters, e.g.:
rpc.multicall([list-of-calls], abort_on_error, process_in_order, pass_result_to_next_call, ...)
Further functionality, like transactional behaviour, "atomic multicalls",
rollbacks etc. are outside of the scope of a RPC-system.
So, I would keep the "Batch" simple, meaning:
- no processing order,
since (a) multiple calls in one Batch which depend on each other
don't belong to the "simple" multicall; and (b) processing several
requests in parallel may really speed things up
- return in the same order as in the call,
since then the client doesn't need to sort the responses
> I am of the view that no
> required return order is of greater benefit long term.
I don't see any benefit of "returning out of order" -- even if we had
streaming JSON-RPC servers -- because:
- With a simple client, the client would always wait for the complete
multicall-response before it processes the responses and continues.
Here, returning the responses in order is better, since the client
doesn't need to sort the responses or use the id to determine to
which call the response belongs.
- So, "returning out of order" could only be useful if the "client" can
handle the responses independently, i.e. only if there are several
independent parts (e.g. threads) in the client. But then, it would
be better/simpler in my opinion, if every independent part communicates
independently with the RPC-server.
regards,
Roland
I would opine for no-order in AND no-order out, since that's what
request id's are for ... And that come with maximum flexibility and most
use-case flexibility.
Regards,
Lorenzo.
Regards, Lorenzo.
Lo.
sorry for my late answer -- I've been on vacation the last weeks.
On Tue, Jul 21, 2009 at 10:09:54AM -0700, Matt (MPCM) wrote:
> @Roland:
> Is this something that we can agree to implement now without an
> implied return order?
I still prefer "return-in-order", since then simple clients don't need to
match the ids, and since I don't know *any* advantage of returning-not-in-order.
The server has to wait for all calls to complete anyway, before sending
the batched-response back. The only possible "advantage" of "not-in-order"
I read here (hope I haven't missed anything -- please tell me if I have) was
that it could be better with some kind of "streaming communication" -- but
there neither are any streaming JSON-encoders/decoders, nor do the usually
used protocols (e.g. HTTP) support such streaming messages.
Additionally, e.g. the OpenSocial-RPC looks quite similar to JSON-RPC 2.0
(except that they omit the "jsonrpc"-field), and also requires in-order.
(http://www.opensocial.org/Technical-Resources/opensocial-spec-v081/rpc-protocol)
There's one additional (minor) "thing" about in-order vs. not-in-order, I
noticed as I read my batched-example again:
Batched Call:
--> [ {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},
{"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},
{"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"},
{"foo": "boo"},
{"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"},
{"jsonrpc": "2.0", "method": "get_data", "id": "9"} ]
<-- [ {"jsonrpc": "2.0", "result": 7, "id": "1"},
{"jsonrpc": "2.0", "result": 19, "id": "2"},
{"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request."}, "id": null},
{"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found."}, id: "5"},
{"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"} ]
When returning in-order, it's clear that the "Invalid Request."-error
belongs to the '{"foo": "boo"}'-call. When returning "not-in-order" you
couldn't tell...
@Matt:
> Should it turn out to make more sense with an implied order we can
> consider adding that restriction in for a later spec revision?
No, it wouldn't make much sense to add/remove such a restriction in a
later revision, since then you would have an additional incompatible
revision...
> That way 2.0 clients that use id's to handle responses would work with
> any later revision that might also require that order be preserved.
> Doing it in the reverse order would cause that not be true.
But newer clients won't work with older servers.
To be able to communicate with older servers and older clients, this would
probably result in servers returning in-order and clients expecting no
order... No, I think that wouldn't work -- we should now define if the
batched response should be in-order or not-in-order and then stick to
this. Everything else would cause confusion and incompatibilities.
regards,
Roland
[in-order vs. not-in-order response in batched calls]
> > Additionally, e.g. the OpenSocial-RPC looks quite similar to JSON-RPC 2.0
> > (except that they omit the "jsonrpc"-field), and also requires in-order.
> > (http://www.opensocial.org/Technical-Resources/opensocial-spec-v081/rp...)
>
> This may be a very good reason for in-order, but I would still say the
> gains are minimal. Below I explain why...
> [...]
> I still do not really see the gain in requiring order, except to match
> the opensocial-rpc.
Ok, if everybody else here is in favour of "not-in-order" responses (as it
seems to me), then I'll update the current proposal accordingly.
If anybody (except me ;)) is against "not-in-order" and for "in-order",
please tell me *now* and tell me *why*. Otherwise the spec will not
require any order in the batch-response.
[error-responses]
> It also amounts to wasted bandwidth for the gain
> of telling the client something it can infer and should have
> prevented. (i.e. For a 100 item batch, with 2 normal requests and 2
> notification requests, we are sending back 96 errors (that the client
> should have known about) and 2 valid responses.)
Right. This "wasted bandwidth" on error always exists, and does not
depend on the "in-order or not-in-order"-definition. But I wouldn't
see it as "wasted bandwidth" -- it does carry information, and tells
the client what went wrong.
If I understand you correctly, you think about omitting such
error-responses which would have '"id": null' in batch-responses, right?
I wouldn't do that, because (a) the returned erros contain information,
and (b) such errors should rarely occur (except the client-library is
extremely buggy), so that you don't win anything by omitting these.
> Could {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid
> Request."}, "id": null} triggered by anything other than something the
> client should have known?
It should only be triggered by an invalid request, which may be caused
by:
- the client sending an invalid request
- some errors on the "connection"
(e.g. corrupted data/lost packets etc. if this isn't prevented
elsewhere)
- a bug in the server
regards,
Roland
This is not at any specific message in this thread.
I do not have any specific issue or suggestion - but the basic thing
to note is -
you are sending data and a half baked set of instructions in json-rpc
- half baked in the sense json-rpc is not turning complete (and i am
not suggesting that it necessarily be TC)
One way to solve all your problems is to send full on javascript and
execute javascript (even today this should be possible out of the box
in .net and java at least and of course the browsers) and then deal
with security :)
As long as you are not using a Turing complete mechanism you will have
issues and that is ok, you just have to make tradeoffs. You need to
keep that in mind especially in the design discussions I am seeing in
this thread.
I don't think I am completely off the mark here - for example the question above
> - we can't make any indication of how the batch should be processed
(In series or parallel? If in series, do we stop for errors? Rollback
a transaction?)
is simply answered by - hey, whatever the block of javascript code the
client sent me is what I am going to do says the server.
I see lot of things like templating mechanisms, configuration
mechanisms etc that start out as 'simple' and then become a mess
trying to get out of the hole of not being TC
(like - oh we now need a conditional config, lets now add an 'if' )
and rpc mechanisms are probably in the same category
Just my 2C, back to lurking
-Antony
No sure how this relates to Turing completeness .. ;P Lo.