[nodejs] Is it beneficial to create an asynchronous function?

2013-06-16 Thread Robert Steckroth
I have a server which parses through a text file and creates a XML page. The XML creation can involve a lot of loops (up to ~8000). I am confused regarding the asynchronous nature of NodeJs. Would the below function benefit from a non-blocking call? Or does the createServer function maintain its

Re: [nodejs] Is it beneficial to create an asynchronous function?

2013-06-16 Thread Angel Java Lopez
Hi! Ummm... makeXmlFromString, beginning at line 83, could directly return the value xmlFile instead of calling a callback. No I/O in its body, so you don't leverage the power of node.js to manage async I/O Maybe, at line 61, when req.on('data') you could start to create the xml, incrementall

Re: [nodejs] Is it beneficial to create an asynchronous function?

2013-06-16 Thread Robert Steckroth
So, how do I get the function to be asynchronous if I added other functionality? Is there a module to import? I just do not get the threading aspect of it all I guess. On Sun, Jun 16, 2013 at 4:37 PM, Angel Java Lopez wrote: > Hi! > > Ummm... makeXmlFromString, beginning at line 83, could direct

Re: [nodejs] Is it beneficial to create an asynchronous function?

2013-06-16 Thread Mark Hahn
> So, how do I get the function to be asynchronous You can't. You could put in setTimeouts with zero delay if you are worried about giving other tasks a chance of running more often. > I just do not get the threading aspect of it all It is actually simple, there is not threading. You can launc

Re: [nodejs] Is it beneficial to create an asynchronous function?

2013-06-16 Thread Andrey
Do you have any numbers to proof that you need to optimise here? How much time does it usually take for makeXmlFromString to complete? Could you post first lines of processed v8.log after running with --profile? If you are sure that this function does block io loop for some significant amount o

Re: [nodejs] Is it beneficial to create an asynchronous function?

2013-06-17 Thread Robert Steckroth
Wow, you have many solutions to that one. I was under the impression that a consistent asynchronous patterned was expected in NodeJs programming. I think I understand how it works now. It just serves users with data when it is time/ready to. I was thinking the wrong way about the whole thing. I did

Re: [nodejs] Is it beneficial to create an asynchronous function?

2013-06-17 Thread Andrey Sidorov
"consistent asynchronous pattern" is expected for IO-bound tasks. CPU-bound solutions are less consistent as 1) it's a little bit outside of node.js scope 2) there are more solutions 3) it depend a lot on domain area (not all people crunch fibonacci numbers) and hardware ( number of CPUs/GPU/vector