-
Notifications
You must be signed in to change notification settings - Fork 186
Batch statements
Phantom also brrings in support for batch statements. To use them, see IterateeBigTest.scala. Before you read further, you should remember batch statements are not used to improve performance.
Read the official docs for more details, but in short batches guarantee atomicity and they are about 30% slower on average than parallel writes at least, as they require more round trips. If you think you're optimising performance with batches, you might need to find alternative means.
We have tested with 10,000 statements per batch, and 1000 batches processed simultaneously. Before you run the test, beware that it takes ~40 minutes.
Batches use lazy iterators and daisy chain them to offer thread safe behaviour. They are not memory intensive and you can expect consistent processing speed even with 1 000 000 statements per batch.
Batches are immutable and adding a new record will result in a new Batch, just like most things Scala, so be careful to chain the calls.
phantom also supports COUNTER
batch updates and UNLOGGED
batch updates.
import com.websudos.phantom.dsl._
Batch.logged
.add(ExampleRecord.update.where(_.id eqs someId).modify(_.name setTo "blabla"))
.add(ExampleRecord.update.where(_.id eqs someOtherId).modify(_.name setTo "blabla2"))
.future()
import com.websudos.phantom.dsl._
Batch.counter
.add(ExampleRecord.update.where(_.id eqs someId).modify(_.someCounter increment 500L))
.add(ExampleRecord.update.where(_.id eqs someOtherId).modify(_.someCounter decrement 300L))
.future()
import com.websudos.phantom.dsl._
Batch.unlogged
.add(ExampleRecord.update.where(_.id eqs someId).modify(_.name setTo "blabla"))
.add(ExampleRecord.update.where(_.id eqs someOtherId).modify(_.name setTo "blabla2"))
.future()
To stay up-to-date with our latest releases and news, follow us on Twitter: @outworkers.
- Issues and questions
- Adopters
- Roadmap
- Changelog
- Tutorials
- Commercial support
- Using phantom in your project
- Primitive columns
- Optional primitive columns
- Collection columns
- Collection operators
- Automated schema generation
- Indexing columns
- Data modeling with phantom
- Querying with phantom
- Asynchronous iterators
- Batch statements
- Apache Thrift integration
- Apache ZooKeeper integration
- The phantom testkit