Erlang comes packed with a Key Value store in the form of the ETS module. This is database is pretty fast and efficient for storing the Erlang terms in memory.
I tried a proof of concept with the PHP extension and I obtained impressive results: Storing 150.000+ items in the ETS in 1 second! All that running on my Macbook Pro.
What I did was to write a PHP class wrapping the calls to the Erlang ETS module like for example:
Maps to this call in Erlang:
public function insert($key, $value)
{
$x = peb_encode("[~a, {~a, ~s}]", array(array(
$this->name,
array($key, $value)
)));
$result = peb_rpc("ets", "insert", $x, $this->link);
return peb_decode($result);
}
> ets:insert(tablename, {key, value}).You can see the full code example here.
So here are the steps:
- Install the PEB extension from source
- Start Erlang with this Command: erl -sname node -setcookie abc
- Create the ETS table: ets:new(test, [set, named_table, public]).
- Save the gist to a file and run it: php ets.php
So while this is a very simple proof of concept, I just wanted to illustrate some of the cool things that can be done with this extension. For example the speed of encoding/decoding from Erlang to PHP is pretty decent as well as the communication speed.
Please let me know your thoughts about it in the comments.
No comments:
Post a Comment