No, that's not entirely accurate. It /may/ be harder to implement
server-side because the server /must/ return an array of responses. You
cannot simply squirt back responses onesy-twosy. That is, the server
/cannot/ treat each component as a single request.
That means at the very least there's additional code, and my impression
is that there's additional hair as well, especially where abnormal
conditions are concerned. That's why I don't favor making this
mandatory. I have a socket-based json-rpc implementation, mostly for
use locally (as an inter-language RPC, rather than for use in web apps).
Batch mode is a nuisance for me, and no payoff, so I probably will keep
my library private and not bother complying with this aspect of the
standard....
cheers,
r
Hi Robert.
I still have it as one of my goals to write up some notes on
socket-based implementations and the issues around compatibility. For
that I need as many real socket-based implementations as possible. So
while I sympathise with your view that it makes certain
implementations harder (my implementation required some significant
refactoring to deal with batch), I hope you can release your library
with the caveat that it does not support batch, rather than not
release it at all.
Cheers,
Rasjid.
I agree that if one designed one's library from the outset to handle
batch requests, it is all pretty straightforward, since (as you note)
a single request is just a batch request of length one, with the
brackets removed. But for socket based servers (plain tcp etc), it
shifts the processing from:
(a) parse request -> process request -> send response
to
(b) parse request (or batch) -> process request(s) -> collate
responses -> send response
For transports like http, you need to link the response to the
specific request anyway, so there is almost no additional work. But
for socket based servers it can mean the addition of a extra layer of
complexity which is otherwise avoided.
So while I agree it is indeed trivial if one starts one's design with
batch in mind, it can be a bit of a pain to retrofit into an (a) style
design.
The above being said, the 2.0 spec is now final, and I think that is a
good thing.
Cheers,
Rasjid.
Say I have a screen that needs to be rendered (web page or a flex UI
or whatever)
Initial display might need data from a set of apis.
Once initial display is done I might need to update only some data.
There are three ways to do that
1. Call a number of apis for each part and then render the page
(rendering incrementally or as a whole is irrelevant for server). Call
the individual apis for the individual parts to be refreshed later.
2. Have a composite api for the whole data and provide separate api for parts.
3. Provide only separate parts apis for parts only and have a batching
mechanism. Client decides what compositions it wants to exercise.
Option 1 and 3 unlink the server design/dev from the client(s) product dept :)
Option 1 is generally slower when you have a sufficiently complex (in
terms of number of distinct parts and the ways they are
combined/organized by the various clients).
Option 3 also allows better request level caching (Sorry, I don't have
the patience to explain).
Option 3 also allows for transactions containing arbitrary set of api calls.
Hence the need for batching.
It should be obvious that option 1 is slower than option 3. If you
quesion whether the slowness is sufficient to warrant the batching
complexity, that's a valid question. If you are disagreeing that 1 is
slower than 3, then I don't have anything to say.
I have run into homegrown protocols that did not have batching and had
to create. Standard protocols that don't provide batching (such as MS
WCF) and had to go for option 2.
If you are still not convinced, ask yourselves why pretty much all
database servers provide for stored procedures.
I have run into that too :) Developed a whole app calling straight
SQL. Found it to be dog slow and had to write stored procs. Suddenly
the app was usable. So whats the difference between stored procs
called from client and individual SQL queries called from client?
answer - batching, yeah may be compilation too :)
A batch mechanism is not needed from a computational power point of
view. It's needed for performance.
-Antony