You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by ben fleis <be...@monkey.org> on 2012/12/06 16:07:30 UTC
Re: 0.8 producer -- many questions
Since the v0.8 protocol wire changes went in, it's time for me to fix my
protocol things. One immediate question:
On Tue, Nov 27, 2012 at 1:32 AM, Joel Koshy <jj...@gmail.com> wrote:
> The requestId for each request-type is written out to the wire (see
> BoundedByteBufferSend)
>
The code I find writes a requestId if it's attached, but looks perfect
content if not. This is the kind of thing that's very hard to infer, since
scanning all of the constructors, etc., is impractical.
https://github.com/apache/kafka/blob/0.8/core/src/main/scala/kafka/network/BoundedByteBufferSend.scala#L42
But I assume this: you are sure that they really exist in all requests? (I
doubt myself, not you, but want to
Thanks,
b
Re: 0.8 producer -- many questions
Posted by Jay Kreps <ja...@gmail.com>.
Cool, so did that make sense? tldr: requests are processed in the order
sent and responses are returned in the order of requests.
-Jay
On Thu, Dec 6, 2012 at 9:40 AM, ben fleis <be...@monkey.org> wrote:
> Ok. This is actually what I did in my first version of the code (the queue
> of outstanding requests). I merely thought that it might offer parallelism
> between variant request types. As you mentioned, increased parallelism is
> a good thing for performance, but my question was more about what is
> promised, and what is not.
>
> Thanks,
>
> ben
>
Re: 0.8 producer -- many questions
Posted by ben fleis <be...@monkey.org>.
Ok. This is actually what I did in my first version of the code (the queue
of outstanding requests). I merely thought that it might offer parallelism
between variant request types. As you mentioned, increased parallelism is
a good thing for performance, but my question was more about what is
promised, and what is not.
Thanks,
ben
Re: 0.8 producer -- many questions
Posted by Jun Rao <ju...@gmail.com>.
Ben,
It doesn't look like that you are subscribing to our mailing list. As a
result, your post doesn't automatically show up in the mailing list and has
to be manually approved. Please subscribe to our mailing list by emailing
to the following addresses.
dev-subscribe@kafka.apache.org <de...@kafka.apache.org>
users-subscribe@kafka.apache.org <de...@kafka.apache.org>
Thanks,
Jun
On Fri, Dec 7, 2012 at 3:08 AM, ben fleis <be...@monkey.org> wrote:
> +1 on keeping the field for sanity checking (it's only 1 byte)
>
> +1 on each API/protocol having a singular version, ie Request+Response are
> a single moving version, even if one side changes w/o the other changing
>
> b
>
Re: 0.8 producer -- many questions
Posted by ben fleis <be...@monkey.org>.
Jay,
You're probably right about the version thing -- I tend toward the
paranoid, but if support tooling is clear and easy to use, it turns out
better for everybody. Especially if they are nicely versioned, and live
nearby actual protocol docs :)
b
Re: 0.8 producer -- many questions
Posted by ben fleis <be...@monkey.org>.
I considered this as well; in my opinion, not all code will be so layered
as the scala code. A topic metadata response would use the same mechanism,
including the [reference]s. So in reality it's not *that* far away from
BNF, but I am asking about more emphasis on layout, and revealing type/size
information when practical. If you like I can type out one for the
response, but I haven't done it yet :)
At the end of the day, the main reason I like to see the protocol breakdown
is simple: I just inspect buffers/packets to see if things look right. Be
they from a debugger, or tcpdump, the packet is the packet is the packet,
and having a clear way to see read the wired data matters. I come from a
networking background, so perhaps I'm just biased in that way.
b
Re: 0.8 producer -- many questions
Posted by Jay Kreps <ja...@gmail.com>.
I agree that BNFs are not the most readable thing in the world, but the
fact is that our protocol has variable length fields and lots of repeated
structures which are pretty confusing in a positional form. In practice I
think the code one writes looks a lot like the BNF (e.g.
readTopicMetadataRequest() calla readRequestHeader() and
readArray(readString)). What does a more complex structure like the
TopicMetadataResponse look like in your style of documentation?
-Jay
On Fri, Dec 7, 2012 at 5:40 AM, ben fleis <be...@monkey.org> wrote:
> First off, let me amend my previous votes: +1 for both ApiKey and
> ApiVersion in all responses, even @ 4 bytes. The number of bytes is
> insignificant, useful in the debugging and multiplex scenarios, even if the
> underlying service doesn't yet support it. (The protocol still can.)
> CorrelationId can clearly be used to the same end, but it's still my
> preference.
>
> Secondly, things changed since yesterday, so now i'm using the doc to
> update my protocol.
>
> Biggest comment -- the visual layout of the wire protocol doesn't reflect
> the way I want to read a protocol. (IMHO, BNF makes sense for token/string
> based protocols, but not so much for binary.) Alignment, byte counts when
> available, etc. would all be fantastic. This comes from my own notes, and
> gives an idea of what I wanted to know while implementing:
>
> StandardRequestHeader:
>
>
> field name | type | bytes | notes
>
>
> ----------------------------------------------------------------------------
> size | int32 | 4 | remaining
> packet size
> api_key | int16 | 2 | currently
> [0,5]
> api_version | int16 | 2 |
> correlation_id | int32 | 4 |
> client_id | int16_string | 2+|s| |
>
> TopicMetadata Request:
>
> field name | type | bytes | notes
>
>
> ----------------------------------------------------------------------------
> <StandardRequestHeader> | 14+|s| |
> len([topic name]) | int32 | 4 |
> [topic name] | [int16_string] | [2+|s|] |
>
> I will have more commentary as I read more, but this is the major thing for
> me.
>
> b
>
Re: 0.8 producer -- many questions
Posted by Jay Kreps <ja...@gmail.com>.
WRT the version I don't think it will really help to catch bugs. It is
definitely possible for us to have protocol bugs, but I don't think that
that version would catch the problem since the person breaking the protocol
would probably not change the version number. I also think it is confusing
for the person implementing the client. Having a version seems to indicate
that we can send back different response versions, which we can't. Should
they handle them? What should they do if they get an unknown version? In
reality we should just not do this and guarantee that we send back the
version they expect.
I think the two things we need to do to ensure this really works is. The
first is to fix the way we are handling serialization, it is currently very
fiddly and error prone. It was okay when there were two requests with a
couple fields each, but isn't working any more. The second is that starting
with the next release we need to reinstate the practice we had with the
previous protocol of saving protocol request and response binaries for each
request from each release and testing that we are properly compatible with
old versions. I think that this is a very effective kind of test and would
catch bugs of the form you describe.
-Jay
On Fri, Dec 7, 2012 at 5:40 AM, ben fleis <be...@monkey.org> wrote:
> First off, let me amend my previous votes: +1 for both ApiKey and
> ApiVersion in all responses, even @ 4 bytes. The number of bytes is
> insignificant, useful in the debugging and multiplex scenarios, even if the
> underlying service doesn't yet support it. (The protocol still can.)
> CorrelationId can clearly be used to the same end, but it's still my
> preference.
>
> Secondly, things changed since yesterday, so now i'm using the doc to
> update my protocol.
>
> Biggest comment -- the visual layout of the wire protocol doesn't reflect
> the way I want to read a protocol. (IMHO, BNF makes sense for token/string
> based protocols, but not so much for binary.) Alignment, byte counts when
> available, etc. would all be fantastic. This comes from my own notes, and
> gives an idea of what I wanted to know while implementing:
>
> StandardRequestHeader:
>
>
> field name | type | bytes | notes
>
>
> ----------------------------------------------------------------------------
> size | int32 | 4 | remaining
> packet size
> api_key | int16 | 2 | currently
> [0,5]
> api_version | int16 | 2 |
> correlation_id | int32 | 4 |
> client_id | int16_string | 2+|s| |
>
> TopicMetadata Request:
>
> field name | type | bytes | notes
>
>
> ----------------------------------------------------------------------------
> <StandardRequestHeader> | 14+|s| |
> len([topic name]) | int32 | 4 |
> [topic name] | [int16_string] | [2+|s|] |
>
> I will have more commentary as I read more, but this is the major thing for
> me.
>
> b
>
Re: 0.8 producer -- many questions
Posted by ben fleis <be...@monkey.org>.
First off, let me amend my previous votes: +1 for both ApiKey and
ApiVersion in all responses, even @ 4 bytes. The number of bytes is
insignificant, useful in the debugging and multiplex scenarios, even if the
underlying service doesn't yet support it. (The protocol still can.)
CorrelationId can clearly be used to the same end, but it's still my
preference.
Secondly, things changed since yesterday, so now i'm using the doc to
update my protocol.
Biggest comment -- the visual layout of the wire protocol doesn't reflect
the way I want to read a protocol. (IMHO, BNF makes sense for token/string
based protocols, but not so much for binary.) Alignment, byte counts when
available, etc. would all be fantastic. This comes from my own notes, and
gives an idea of what I wanted to know while implementing:
StandardRequestHeader:
field name | type | bytes | notes
----------------------------------------------------------------------------
size | int32 | 4 | remaining
packet size
api_key | int16 | 2 | currently
[0,5]
api_version | int16 | 2 |
correlation_id | int32 | 4 |
client_id | int16_string | 2+|s| |
TopicMetadata Request:
field name | type | bytes | notes
----------------------------------------------------------------------------
<StandardRequestHeader> | 14+|s| |
len([topic name]) | int32 | 4 |
[topic name] | [int16_string] | [2+|s|] |
I will have more commentary as I read more, but this is the major thing for
me.
b
Re: 0.8 producer -- many questions
Posted by ben fleis <be...@monkey.org>.
+1 on keeping the field for sanity checking (it's only 1 byte)
+1 on each API/protocol having a singular version, ie Request+Response are
a single moving version, even if one side changes w/o the other changing
b
Re: 0.8 producer -- many questions
Posted by Jay Kreps <ja...@gmail.com>.
These are all very good questions. Thanks for being lazy and trying the
documentation, this feedback is helpful.
- I added documentation on the ApiKey values for each request type to the
wiki.
- We are baselining all versions to 0, since we redid all the apis (looking
at the code, I see we left a few at 1 in our own producer, so I need to
change those). Since there is effectively only one version of the protocol
right now we aren't checking this field.
With respect to versioning the response, you are assuming the problem is
with you but I actually think the problem is with that field. I think the
fact is we hadn't rigorously thought through and documented how this would
work. So, now being the very last moment, would be a good time to do that.
Here is what I recall of the thinking: First we thought it would be better
to version on a per-api basis rather than version the whole protocol since
many people implement just use a subset of the apis. So the intention was
to have a separate version number per API. Our thought, iirc, was to
version changes in both request and response separately. So if we added a
field to the request it would be move to version 1 but the response would
remain version 0 since it hadn't changed. Thinking about this from the
client implementors point of view, though, this is not a good thing. In
practice we are going to need to specify the correspondence between the
request version and the response version. And if we do this why not just
make them the same number? And if they are the same number why not omit the
response version entirely?
Thinking about it, I don't think that field is really adding value and I
think we should just delete it. The only possible value would be for a
client checking that it is in fact getting the format version that it
expects, but I don't feel that that is something that needs to be checked
on each request.
That's slightly embarrassing, but I say we just delete it.
-Jay
On Thu, Dec 6, 2012 at 3:12 PM, Milind Parikh <mi...@gmail.com>wrote:
> I am in the process of updating my erlang producer/consumer client to 0.8.
>
> Being lazy, I don't really want to go to Scala code. So I am just going
> through
>
> https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
> .<
> https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
> >Most
> things are clear and clearer with discussion in this thread.
>
> However a few queries:
>
> RequestObject
> (a) What are the specific values for the different requests in the
> ApiKey?
> (b) What are the specific legal values for ApiVersions? I assume that
> this might change for future versions of kafka.
>
> ResponseObject
> (a) Would there be a difference between ResponseVersion and the
> ApiVersions of the RequestObject? Would be possible, in the future, to
> request ApiVersion of X and get a ResponseVersion of Y? How would the
> cliient know how to parse ResponseVersion of Y. This makes me think that I
> don't understand the motivation behind ApiVersions. Can someone shed some
> light?
>
> Thanks
> Milind
>
>
>
>
>
>
>
> On Thu, Dec 6, 2012 at 9:21 AM, Jay Kreps <ja...@gmail.com> wrote:
>
> > Also we are trying to document all this stuff well with the 0.8 release.
> > What could I do to improve this document:
> >
> >
> https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
> >
> > Its kind of hard to write good documentation, so any feedback would be
> > appreciated.
> >
> > -Jay
> >
> >
> > On Thu, Dec 6, 2012 at 9:20 AM, Jay Kreps <ja...@gmail.com> wrote:
> >
> > > Hi Ben,
> > >
> > > If I understand your question, you are asking if it is possible to
> > > decouple or pipeline the sending of the request and the reading of the
> > > response. E.g. do something like
> > > send(req1)
> > > send(req2)
> > > recv(resp1)
> > > recv(resp2)
> > > I think your question is, if I do this how do I know what response goes
> > to
> > > what request.
> > >
> > > The answer is that the server guarantees in-order processing of
> requests
> > > on a given connection. So correlating requests to responses can be done
> > by
> > > keeping a queue of as-yet unanswered requests. In 0.8 we also added an
> > > official correlation id (an integer field you can set that the server
> > > passes back unchanged in the response. This is meant to help do tracing
> > > across client and server and may help to debug your implementation. We
> do
> > > not currently send back the API key since there is only one correct
> value
> > > that could have--whatever the api of the corresponding request was.
> > >
> > > One caveat is that the server doesn't really fully pipeline request
> > > processing at this time so if you do pipeline you may not get quite as
> > much
> > > parallelism as you expect (you can never get full parallelism because
> of
> > > the ordering guarantee). But in the current code until a response is
> sent
> > > for req1 the server won't start reading req2. This is not hard to fix
> and
> > > we will get to it in the next major release I think.
> > >
> > > -Jay
> > >
> > >
> > >
> > > On Thu, Dec 6, 2012 at 7:50 AM, ben fleis <be...@monkey.org> wrote:
> > >
> > >> I just realized something important. The BoundedByteBufferSend
> comment
> > >> above is not in sync with my original question. I was asking about
> > >> Responses -- meaning, can I multiplex off a single socket, and when
> > >> reading
> > >> an arbitrary response, switch on request_id to the right handler?
> > >>
> > >> In the blocking console sync client (which is the only trivial way to
> > >> follow the code that I've found -- please enlighten if there's an
> async
> > >> thing I can easily trace), this is a non issue, since you request,
> wait,
> > >> parse expected response.
> > >>
> > >> Or do I need instead to just open separate sockets? (Not a big deal,
> > but
> > >> nice to understand clearly.)
> > >>
> > >> ben
> > >>
> > >
> > >
> >
>
Re: 0.8 producer -- many questions
Posted by Milind Parikh <mi...@gmail.com>.
I am in the process of updating my erlang producer/consumer client to 0.8.
Being lazy, I don't really want to go to Scala code. So I am just going
through
https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol.<https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol>Most
things are clear and clearer with discussion in this thread.
However a few queries:
RequestObject
(a) What are the specific values for the different requests in the
ApiKey?
(b) What are the specific legal values for ApiVersions? I assume that
this might change for future versions of kafka.
ResponseObject
(a) Would there be a difference between ResponseVersion and the
ApiVersions of the RequestObject? Would be possible, in the future, to
request ApiVersion of X and get a ResponseVersion of Y? How would the
cliient know how to parse ResponseVersion of Y. This makes me think that I
don't understand the motivation behind ApiVersions. Can someone shed some
light?
Thanks
Milind
On Thu, Dec 6, 2012 at 9:21 AM, Jay Kreps <ja...@gmail.com> wrote:
> Also we are trying to document all this stuff well with the 0.8 release.
> What could I do to improve this document:
>
> https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
>
> Its kind of hard to write good documentation, so any feedback would be
> appreciated.
>
> -Jay
>
>
> On Thu, Dec 6, 2012 at 9:20 AM, Jay Kreps <ja...@gmail.com> wrote:
>
> > Hi Ben,
> >
> > If I understand your question, you are asking if it is possible to
> > decouple or pipeline the sending of the request and the reading of the
> > response. E.g. do something like
> > send(req1)
> > send(req2)
> > recv(resp1)
> > recv(resp2)
> > I think your question is, if I do this how do I know what response goes
> to
> > what request.
> >
> > The answer is that the server guarantees in-order processing of requests
> > on a given connection. So correlating requests to responses can be done
> by
> > keeping a queue of as-yet unanswered requests. In 0.8 we also added an
> > official correlation id (an integer field you can set that the server
> > passes back unchanged in the response. This is meant to help do tracing
> > across client and server and may help to debug your implementation. We do
> > not currently send back the API key since there is only one correct value
> > that could have--whatever the api of the corresponding request was.
> >
> > One caveat is that the server doesn't really fully pipeline request
> > processing at this time so if you do pipeline you may not get quite as
> much
> > parallelism as you expect (you can never get full parallelism because of
> > the ordering guarantee). But in the current code until a response is sent
> > for req1 the server won't start reading req2. This is not hard to fix and
> > we will get to it in the next major release I think.
> >
> > -Jay
> >
> >
> >
> > On Thu, Dec 6, 2012 at 7:50 AM, ben fleis <be...@monkey.org> wrote:
> >
> >> I just realized something important. The BoundedByteBufferSend comment
> >> above is not in sync with my original question. I was asking about
> >> Responses -- meaning, can I multiplex off a single socket, and when
> >> reading
> >> an arbitrary response, switch on request_id to the right handler?
> >>
> >> In the blocking console sync client (which is the only trivial way to
> >> follow the code that I've found -- please enlighten if there's an async
> >> thing I can easily trace), this is a non issue, since you request, wait,
> >> parse expected response.
> >>
> >> Or do I need instead to just open separate sockets? (Not a big deal,
> but
> >> nice to understand clearly.)
> >>
> >> ben
> >>
> >
> >
>
Re: 0.8 producer -- many questions
Posted by Jay Kreps <ja...@gmail.com>.
Also we are trying to document all this stuff well with the 0.8 release.
What could I do to improve this document:
https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
Its kind of hard to write good documentation, so any feedback would be
appreciated.
-Jay
On Thu, Dec 6, 2012 at 9:20 AM, Jay Kreps <ja...@gmail.com> wrote:
> Hi Ben,
>
> If I understand your question, you are asking if it is possible to
> decouple or pipeline the sending of the request and the reading of the
> response. E.g. do something like
> send(req1)
> send(req2)
> recv(resp1)
> recv(resp2)
> I think your question is, if I do this how do I know what response goes to
> what request.
>
> The answer is that the server guarantees in-order processing of requests
> on a given connection. So correlating requests to responses can be done by
> keeping a queue of as-yet unanswered requests. In 0.8 we also added an
> official correlation id (an integer field you can set that the server
> passes back unchanged in the response. This is meant to help do tracing
> across client and server and may help to debug your implementation. We do
> not currently send back the API key since there is only one correct value
> that could have--whatever the api of the corresponding request was.
>
> One caveat is that the server doesn't really fully pipeline request
> processing at this time so if you do pipeline you may not get quite as much
> parallelism as you expect (you can never get full parallelism because of
> the ordering guarantee). But in the current code until a response is sent
> for req1 the server won't start reading req2. This is not hard to fix and
> we will get to it in the next major release I think.
>
> -Jay
>
>
>
> On Thu, Dec 6, 2012 at 7:50 AM, ben fleis <be...@monkey.org> wrote:
>
>> I just realized something important. The BoundedByteBufferSend comment
>> above is not in sync with my original question. I was asking about
>> Responses -- meaning, can I multiplex off a single socket, and when
>> reading
>> an arbitrary response, switch on request_id to the right handler?
>>
>> In the blocking console sync client (which is the only trivial way to
>> follow the code that I've found -- please enlighten if there's an async
>> thing I can easily trace), this is a non issue, since you request, wait,
>> parse expected response.
>>
>> Or do I need instead to just open separate sockets? (Not a big deal, but
>> nice to understand clearly.)
>>
>> ben
>>
>
>
Re: 0.8 producer -- many questions
Posted by Jay Kreps <ja...@gmail.com>.
Hi Ben,
If I understand your question, you are asking if it is possible to decouple
or pipeline the sending of the request and the reading of the response.
E.g. do something like
send(req1)
send(req2)
recv(resp1)
recv(resp2)
I think your question is, if I do this how do I know what response goes to
what request.
The answer is that the server guarantees in-order processing of requests on
a given connection. So correlating requests to responses can be done by
keeping a queue of as-yet unanswered requests. In 0.8 we also added an
official correlation id (an integer field you can set that the server
passes back unchanged in the response. This is meant to help do tracing
across client and server and may help to debug your implementation. We do
not currently send back the API key since there is only one correct value
that could have--whatever the api of the corresponding request was.
One caveat is that the server doesn't really fully pipeline request
processing at this time so if you do pipeline you may not get quite as much
parallelism as you expect (you can never get full parallelism because of
the ordering guarantee). But in the current code until a response is sent
for req1 the server won't start reading req2. This is not hard to fix and
we will get to it in the next major release I think.
-Jay
On Thu, Dec 6, 2012 at 7:50 AM, ben fleis <be...@monkey.org> wrote:
> I just realized something important. The BoundedByteBufferSend comment
> above is not in sync with my original question. I was asking about
> Responses -- meaning, can I multiplex off a single socket, and when reading
> an arbitrary response, switch on request_id to the right handler?
>
> In the blocking console sync client (which is the only trivial way to
> follow the code that I've found -- please enlighten if there's an async
> thing I can easily trace), this is a non issue, since you request, wait,
> parse expected response.
>
> Or do I need instead to just open separate sockets? (Not a big deal, but
> nice to understand clearly.)
>
> ben
>
Re: 0.8 producer -- many questions
Posted by ben fleis <be...@monkey.org>.
I just realized something important. The BoundedByteBufferSend comment
above is not in sync with my original question. I was asking about
Responses -- meaning, can I multiplex off a single socket, and when reading
an arbitrary response, switch on request_id to the right handler?
In the blocking console sync client (which is the only trivial way to
follow the code that I've found -- please enlighten if there's an async
thing I can easily trace), this is a non issue, since you request, wait,
parse expected response.
Or do I need instead to just open separate sockets? (Not a big deal, but
nice to understand clearly.)
ben
Re: 0.8 producer -- many questions
Posted by Joel Koshy <jj...@gmail.com>.
My bad - you're right. I either missed that bit or was looking at the 0.7
code. Hopefully the remainder of this thread answers your original question.
On Thu, Dec 6, 2012 at 7:07 AM, ben fleis <be...@monkey.org> wrote:
> Since the v0.8 protocol wire changes went in, it's time for me to fix my
> protocol things. One immediate question:
>
>
> On Tue, Nov 27, 2012 at 1:32 AM, Joel Koshy <jj...@gmail.com> wrote:
>
> > The requestId for each request-type is written out to the wire (see
> > BoundedByteBufferSend)
> >
>
> The code I find writes a requestId if it's attached, but looks perfect
> content if not. This is the kind of thing that's very hard to infer, since
> scanning all of the constructors, etc., is impractical.
>
>
>
> https://github.com/apache/kafka/blob/0.8/core/src/main/scala/kafka/network/BoundedByteBufferSend.scala#L42
>
> But I assume this: you are sure that they really exist in all requests? (I
> doubt myself, not you, but want to
>
>
> Thanks,
>
> b
>