Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use fibers and when to use co-routines in Tarantool?

Tags:

tarantool

In Tarantool, are fibers used when the Lua code author wants Tarantool to schedule the execution? Are co-routines (in the Tarantool/LuaJIT process) used when the Lua code author wants to be in control of the execution?

like image 927
dgo.a Avatar asked Mar 22 '16 10:03

dgo.a


1 Answers

In Tarantool, fibers are synonymous with coroutines. The fibers are more integrated to Tarantool I/O etc, you should use them instead of lua coroutines. We suggest you always use our fibers, rather than Lua coroutines, since they are more powerful. Our entire I/O stack is integrated with them: sockets, files, net.box, mysql, postgresql, etc.

Link to docs: http://tarantool.org/doc/reference/fiber.html

There are some tasks that coroutines could be used for, like iterators. It is perfectly valid to use both coroutines and fibers simultaneously but that may cause a confusion. Coroutine yield may fail with an infamous attempt to yield across C-call boundary, while fibers work in this situation.

like image 63
Vasiliy Soshnikov Avatar answered Sep 22 '22 08:09

Vasiliy Soshnikov