some questions regarding tora

78 views
Skip to first unread message

Munir Hussin

unread,
Aug 20, 2016, 5:04:47 AM8/20/16
to Haxe
Hello, I've set up tora to run as fcgi on an nginx server on digitalocean.com.
The tora version used is the github latest version.
Haxe is 3.2.1 using apt-get.

I have some questions regarding the workings of tora.

1. Why does the following code display all at once (after a 10s delay) instead of showing each number one at a time per second?

import neko.Lib;
import neko.Web;

class Index
{
    public static var count:Int = 0;
    
    public static function main():Void
    {
        Web.cacheModule(start);
        start();
    }
    
    public static function start():Void
    {
        Web.setHeader("Content-Type", "text/plain");
        Sys.println('Hello World! count: $count, is tora: ${Web.isTora}');
        
        for (i in 0...10)
        {
            Sys.println('$i');
            Web.flush();        // flush isn't working?
            Sys.sleep(1);
        }
        
        Sys.println('done! count: $count');
        ++count;
    }
}

flush is supposed to flush the buffer to the browser? You can see the output at http://www.moonaire.com


2. I'd also like to understand tora's concurrency. It's multi-threaded right? And I assume it's from a pool of x threads. But from online articles, it mentioned that cacheModule will keep a single instance of my above program (making that static count variable work)... so for my above program, it becomes single threaded again? So if I happen to have some slower codes, it'll block for all visitors to the website?

The above program is also meant to test that. I opened 2 tabs, and went to www.moonaire.com on each, about a second apart. The first tab loads in about 10s, which is expected. The second tab loads 10s after the first tab has loaded, bringing the duration to about 21s.

How does the multi-threading work?


Thanks in advance for any explanations.

Constantine

unread,
Aug 21, 2016, 7:06:00 PM8/21/16
to Haxe
Hello.

1. When fcgi for tora was written nginx has very limited support of fastcgi, only basic features and does not support flush. Dont know anything about current status.

2. Yes, Tora is multi-threaded but dont start all threads at load. Start new thread something like every 10 requests (dont remember actual numbers)

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Munir Hussin

unread,
Aug 21, 2016, 9:54:59 PM8/21/16
to Haxe
Hello Constantine. The explanation helps, thanks.

Looks like this means with fcgi/nginx, long polling is not possible.

Constantine

unread,
Aug 22, 2016, 4:08:43 AM8/22/16
to Haxe
Actually using long polling request in 2016 is not good idea, try to switch on WebSockets
Haxe, nginx (since 1.3.13) and browsers (http://caniuse.com/#feat=websockets) has good support of it

Munir Hussin

unread,
Aug 22, 2016, 7:29:34 AM8/22/16
to Haxe
Thanks. Looks like WebSockets is the way to go.
Reply all
Reply to author
Forward
0 new messages