4 ms·
Liked the post! Interesting point about allocating too many Writables. This problem is an indication that *Writable classes are poorly designed. Instead of ha
by jganetsk 17y ago
Liked the post!
Interesting point about allocating too many Writables. This problem is an indication that *Writable classes are poorly designed. Instead of having public constructors, they should each have some sort of static method, akin to that of a factory class, that implements some sort of intelligent pooling and reuse.
Also, NullWritable is awesome! I don't think you mentioned it. Very useful for counters!
- tlipcon 17y agoThe issue with intelligent pooling is that you (a) might end up with a lot of bookkeeping, or (b) people will forget to return things to the pool. It's way easier to do that kind of design in C++ where you can use scope and copy constructors to automatically refcount and then return back. NullWritable is pretty useful sometimes, but what's wrong with Counter objects for counters?
- jganetsk 17y agoHere's an example of improving the design of your interfaces to improve the problem... The mapper function now receives two extra arguments, one Writable of key type and one Writable of value type. The emit method now has zero arguments. When called, it emits the key-value pair represented by the Writables passed in to the mapper function. Now, you are forced to use and reuse the Writable objects passed in to your mapper. Sure, you can allocate new ones, but they would be worthless since you can't do anything with them. This would, hopefully, stop programmers from allocating them. No need to explicitly return things to any pools.