<div>Hi,</div>
<div> </div>
<div>To illustrate Kenneths point an experience I had today:</div>
<div> </div>
<div>I wanted to answer Ahmeds question (recently on the list) about the use of the new version of erlsom in the yaws soap library. It turned out that this would not use the new mode of erlsom that works directly on binaries. I wondered what the performance impact would be.</div>
<div> </div>
<div>I did a little test: how many soap requests could yaws handle on my PC (a simple laptop running windows XP, with the client and the server running on the same machine)? The answer disappointed me: around 25.</div>
<div> </div>
<div>Now I wondered how much of this would be due to the XML encoding, and would working directly on binaries make a difference. I tried how often Erlang could encode and decode a message in 1 second. Answer: 3500 times.</div>
<div> </div>
<div>Conclusion: erlsom in binary mode or in the 'old' list mode, xmerl, or a C driver: it would not make any difference in this case, as far as performance is concerned. </div>
<div> </div>
<div>All the same, if you decide to continue your attempt to use a C driver, I would be very interested to know what the result is in terms of speed compared to erlsom or xmerl. It would be great if you could let me know.</div>
<div> </div>
<div>Regards,</div>
<div>Willem<br><br></div>
<div class="gmail_quote">2008/4/2 Kenneth Lundin <<a href="mailto:kenneth.lundin@gmail.com" target="_blank">kenneth.lundin@gmail.com</a>>:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">In the documentation you can read how to write an asynchronous driver.<br>You find it here <a href="http://www.erlang.org/doc/apps/erts/driver.html#6.5" target="_blank">http://www.erlang.org/doc/apps/erts/driver.html#6.5</a>.<br>
It's part of the ERTS users guide.<br><br>It is a well known fact that drivers (the most common synchronous ones) block<br>the VM during their execution. You must be very careful to secure that you don't<br>execute for too long in those drivers.<br>
<br>Are you really sure that the speed for parsing this in Erlang is not enough?<br>You can even use native code generation with HiPE. By coding this in Erlang you<br>avoid the problems you have with the driver.<br><br>/Kenneth<br>
<div>
<div></div>
<div><br>On 4/2/08, <a href="http://tate.zhou.cn/" target="_blank">tate.zhou.cn</a> <<a href="mailto:tate.zhou.cn@gmail.com" target="_blank">tate.zhou.cn@gmail.com</a>> wrote:<br>><br>> Hi , guys:<br>><br>
><br>> I worte a c driver for parsing xml pieces. The driver works , but when the<br>> c driver invoked , the erlang emulator will be halted until the execution<br>> of c driver completed. during the execution of the c driver code, other<br>
> process of erlang get no chance to be execute , evenif the usetage of cpu is<br>> around 50% (My cpu is duo core 2 ).<br>><br>> Does anybody have any idea about this issues?<br>><br>> Any infomation about how to write a async driver is appreciate.<br>
><br>><br>> List below is pieces of my erl code and c dirver code:<br>><br>> The execution of ?INFO_MSG in test_async_normal will start until test_async<br>> complete£¬ although the execution time of test_async is more than 2<br>
> seconds.<br>><br>><br>><br>><br>><br>><br>> erlang:<br>> ==========================================<br>><br>> test_async_newpid() -><br>><br>><br>> PID = spawn(?MODULE, test_async_normal,[""]),<br>
><br>> PID2 = spawn(?MODULE, test_async,[""]),<br>><br>> ?INFO_MSG("New Pid for port communication:",[PID]),<br>><br>><br>> ok.<br>><br>><br>> test_async_normal(Data) -><br>
><br>><br>> timer:sleep(2* 1000),<br>> ?INFO_MSG("Hi , I am in new Pid:",[erlang:self()]),<br>><br>> ok.<br>><br>> test_async (Data) -><br>><br>> Port = open_port({spawn, vbp_xmlhandler}, [binary]),<br>
><br>> Bin = erlang:list_to_binary("hello , i come from erlang: "),<br>> %load_xml_bin(),<br>><br>><br>> Port ! {self(), {command, Bin}},<br>><br>> Ret_str = return_port_data(Port),<br>
><br>><br>> ?INFO_MSG("Return from port : ~p~n",[Ret_str]),<br>><br>> % ?INFO_MSG("Return from port : ~s",[Res]),<br>><br>> port_close(Port),<br>><br>><br>><br>
> ok.<br>><br>><br>><br>> return_port_data(Port) -><br>> receive<br>> {Port, {data, Data}} -><br>> Data<br>> end.<br>><br>><br>> ====================================================<br>
><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>> C driver code :<br>><br>> -----------------------------------------------------<br>> static ErlDrvEntry vbp_xmlhandler_entry = {<br>
> NULL, /* init */<br>> vbp_xmlhandler_start,<br>> vbp_xmlhandler_stop,<br>> vbp_xmlhandler_async, /* output */<br>> NULL, /* ready_input */<br>> NULL, /* ready_output */<br>
> "vbp_xmlhandler", /* the name of the<br>> driver */<br>> NULL, /* finish */<br>> NULL, /* handle */<br>> NULL,<br>> NULL, /* timeout */<br>> NULL, /* outputv */<br>
> NULL, /* ready_async */<br>> NULL, /* flush */<br>> NULL, /* call */<br>> NULL /* event */<br>> };<br>> DRIVER_INIT(vbp_xmlhandler) /* must match name in driver_entry */<br>> {<br>
> return &vbp_xmlhandler_entry;<br>> }<br>><br>><br>><br>> /*<br>> // async interface for handle command.<br>> //<br>> */<br>> static void vbp_xmlhandler_async(ErlDrvData handle, char *buff, int<br>
> bufflen){<br>> iostream* stream;<br>> char* test_data;<br>> char *in_data;<br>> int len;<br>> int i ;<br>> int loop_count;<br>> expat_data* d = (expat_data*)handle;<br>><br>> len = bufflen;<br>
><br>><br>> stream = create_stream();<br>><br>> // force a lot of cpu time to be consumed in current invocation.<br>> loop_count = 1000000 * 80;<br>> for(i = 0;i <loop_count ;i++ ){<br>> in_data = malloc(20);<br>
><br>> free(in_data);<br>> }<br>> in_data = malloc(len + 1);<br>> memset(in_data,0,len +1);<br>> memcpy(in_data,buff,len);<br>> write_str_to_stream(stream,in_data);<br>> free(in_data);<br>><br>
> write_str_to_stream(stream," [append by c driver]");<br>><br>> driver_output(d ->port, stream->buff, stream->index);<br>><br>> free_stream(stream);<br>> }<br>><br>><br>><br>
><br>><br>><br></div></div>> _______________________________________________<br>> erlang-questions mailing list<br>> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>><br>_______________________________________________<br>erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br><a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a></blockquote>
</div><br>