facebookarchive / swift

An annotation-based Java library for creating Thrift serializable types and services.
Apache License 2.0
900 stars 297 forks source link

[wishlist] Iterable thrift structures #207

Closed manukranthk closed 6 years ago

manukranthk commented 10 years ago

Currently the way we can have iterable thrift structures is by having a List of items. We can access the items of the list only after we have the entire list. Also, we need to de-serialize all the elements in order to read even the very first element. This might add unnecessary memory pressure on the system.

allComputableThings commented 9 years ago

It looks straightforward to build a codec to do this. However, as far as vanilla thrift RPC spec goes, isn't this a limitation of its design?

By default, I think that the auto-generated client code won't result a result until the entire 'thing' has been received because the thrift type language doesn't know about lists. To do what you want you could either. It might be worth contact the thrift mailing list:

I'd be interested in how people workaround this limitation. It seems possible, for example to have a API return an object that represents an iterator reference and then make additional API calls to get more items:

TIterator<TUser> queryDB();
List<User> getMore( TIterator<TUser>, int pageSize );

where

class TIterator{ int iteratorID; }

and the sever maintains a map:

activeIterators Map<int, Iterator >

per active connection.

queryDB adds a record to the map. getMore read from the map.

The map would need to be cleaned (and any open iterators closed) if the connection closed or timed-out.

I'd be very interested to hear how other people solve this issue as I'm facing it myself.

andrewcox commented 9 years ago

Yeah, the way thrift currently works, you can't get what you want (to start iterating through results before the whole result arrives).

However, we are considering potentially adding streaming support to fbthrift, for exactly this kind of thing, after which point we'd add it to swift as well.

People who need this now here at FB, do pretty much what you're saying: they break the result up into chunks, and make multiple calls to get it.

ghost commented 9 years ago

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.