[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Moai Cloud - Lua-based Web Services
- From: David Hollander <dhllndr@...>
- Date: Tue, 12 Jul 2011 17:38:52 -0500
>�Where I KNOW I'm not getting the speed is my connection to CouchDB; it's on the same host,�
If you just need a key-value store on the same host have you considered using Tokyo Cabinet ? [1]
It's the fastest on-disk persistant hashmap of non-fixed size, and has an excellent binding for Lua. It buffers very efficiently when writing to disk
so you can do 1million inserts per second, should blow CouchDB out of the water. In many situations, its best to just embed TokyoCabinet directly in your program and not worry about the�occasional�disk seek. Alternatively, you can isolate it in a fork using an RPC library, or use the Tokyo Tyrant server to access it asynchronously.�TokyoTyrant allows you to write your queries as Lua functions embedded directly in the database server.
Currently, I use tokyocabinet to store serialized Lua into a hashmap, which is much faster to reload than using a JSON intermediary.
To make it nonblocking on disk seeks, I'm currently developing an async RPC format that lets me roll datastores by doing the following:
db = tokyocabinet.hdb()
db:open('posts.hdb', hdb.OCREAT+hdb.OWRITER)
data = "" -- creates a forked process
pagecache = cache(10)
-- define database method "tags"
data['tags'] = function(tagname)
� results={}
� for key, post in db:pairs() do
� � post = loadstring('return '..post)() �-- load serialized lua table
� � if post.tags:match(tagname) then
� � � table.insert(results, post)
� � end
� end
� return results
end
-- define a handler that will call our database method
pagecache['tag/([^/]+)'] = function(tag_name)
� �data.tags(tag_name, function(results)
� � � � --do stuff with results table when database calls back
� �end)
end
On Tue, Jul 12, 2011 at 3:32 PM, Tim Mensch
<tim-lua-l@bitgems.com> wrote:
On 7/12/2011 2:27 PM, Matt Towers wrote:
> On Jul 12, 2011, at 12:57 , Tim Mensch wrote:
>> But I was in a hurry and I couldn't find a ready-made MongoDB interface for Lua.
> Here ya go: �
https://github.com/moai/luamongo
I guess I should have asked last week. :)
Everything is stable now, and there's no way I'm going to touch it, but
thanks for the link. If I have speed issues that I track to CloudDB,
I'll use this for sure -- and for my next game I'll go there first. :)
Tim