| Author |
Message |
< Erlang ~ blocking vs non-blocking TCP task, does it matter in erlang |
| garyng |
Posted: Wed Aug 15, 2007 1:00 pm |
|
|
|
Joined: 15 Aug 2007
Posts: 7
|
Hi,
I am totally new to erlang but found it to be very interesting system(both language and the various modules).
I see that there is a turtorial about building non-blocking TCP daemon and am wondering, does it matter ?
I have recently working on LUA and built a coroutine(event driven) httpd where non-blocking is a must and the performance is good. It does suffer from one weakness in that if any one of the request is blocked(say executing a SQL statement), the whole server stucked. Which is also one of the reason I look for erlang which as far as I know has preemptive thread yet the thread is still very light weight thus can handle lots of simultaneous connection, in additional of expanding outward to multiple machines.
So why not just spawn a new thread for each accepted connection and just coded it as a serial operation and let it block as needed ? |
|
|
| Back to top |
|
| Mazen |
Posted: Wed Aug 15, 2007 1:07 pm |
|
|
|
User
Joined: 20 Jul 2006
Posts: 164
Location: London
|
I'm not sure I follow what you mean
He do spawn of a process for each connection, that is the whole "non-blocking" part. The fact that the process he spawned is blocked is fine, as long as he is not blocking for more incoming connections.
Or maybe I'm mistaken about his code  |
|
|
| Back to top |
|
| garyng |
Posted: Thu Aug 16, 2007 1:08 am |
|
|
|
Joined: 15 Aug 2007
Posts: 7
|
I mean what is the rationale for an async accept ?
If each thread(including the listen/accept one) runs independently, would just having a blocked accept call still work ? I was thinking there must be some reason why this is needed as it needs more code.
I have a question on how to do duplex mode properly.
In HTTP/1.1, there is a keep-alive/pipeline mode which means multiple request can be sent. While a serial version would be to read all of them(say into a list) then start a sender thread to fullfil the requests. There could be a scenario that the client send a request and a sender thread is started. In the mean time, another request comes in. However, since the previous sender hasn't finished its job, a new thread cannot be started(or must wait to really send) before all the previous one finish.
In my LUA version, I just have a loop and a queue which does it in turn. But erlang being FP, there is no "append to queue" as all values are supposed to be immutable.
How should this pattern be done in erlang style ? |
|
|
| Back to top |
|
| asergey |
Posted: Thu Aug 16, 2007 4:06 am |
|
|
|
User
Joined: 12 Mar 2005
Posts: 313
|
[quote]I mean what is the rationale for an async accept ?
If each thread(including the listen/accept one) runs independently, would just having a blocked accept call still work ? I was thinking there must be some reason why this is needed as it needs more code. [/quote]
The subject of the tutorial says "... using OTP principles". These principles define application building guidelines that allow an application to use features such as dynamic code upgrades. Orphan processes not built using standard OTP behaviors that rely on blocking calls are quite tricky to implement so that they would be compliant with OTP guidelines.
[quote]There could be a scenario that the client send a request and a sender thread is started. In the mean time, another request comes in. However, since the previous sender hasn't finished its job, a new thread cannot be started(or must wait to really send) before all the previous one finish. [/quote]
You would need to separate request-handling code from transport handling code. For each incoming TCP connection a separate transport-handling process would be created. This process would deal with receiving packets from the network and deliminating them into requests. Upon collecting a full request message the transport process would spawn a different process that would handle that request and communicate response back to the transport process.
-Serge |
|
|
| Back to top |
|
| garyng |
Posted: Thu Aug 16, 2007 7:46 am |
|
|
|
Joined: 15 Aug 2007
Posts: 7
|
Ah, it is clearer now. So all OTP prinicpled must be purely message driven and non-blocking in its major code path(and the accept thread is one, but I assume the actual handler doesn't need to be one ?)
That trigger me another question, what if I must have some potentially blocking code, say long running SQL select statement ? I would some how need to spawn a thread then send back a message when it is finished ? In other words, if there is a chance of blocking, I need to turn in into a seperate state ?
Quote: You would need to separate request-handling code from transport handling code. For each incoming TCP connection a separate transport-handling process would be created. This process would deal with receiving packets from the network and deliminating them into requests. Upon collecting a full request message the transport process would spawn a different process that would handle that request and communicate response back to the transport process.
That is what I think but I don't know how to do it in erlang. In LUA(or other non-FP language), I can have an intermediate space to store these request but not in FP. When I have collected enough info for a request, I have to spawn something and move on but this spawned process(say S2) before another send process(S1) is done which may communicate back to R(the request). My question is, how can R know that there is S2(or S3,S4 ...) waiting when S1 tell it, "I am done".
In Haskell, may be I can have a monad that carries these "pending sent functions". |
|
|
| Back to top |
|
| asergey |
Posted: Thu Aug 16, 2007 10:21 am |
|
|
|
User
Joined: 12 Mar 2005
Posts: 313
|
[quote]Ah, it is clearer now. So all OTP prinicpled must be purely message driven and non-blocking in its major code path(and the accept thread is one, but I assume the actual handler doesn't need to be one ?) [/quote]
Every interprocess blocking call in Erlang except for very few (such as erlang:port_call/3) relies on the following pattern:
[code]
blocking_call(A, B, Timeout) ->
A ! B,
receive
Clause1 -> ...;
Clause2 -> ...;
... ->
after Timeout ->
timeout
end.
[/code]
While this pattern doesn't block VM as a whole, it blocks the process evaluating this code at the receive statement. If the process is to be notified of some critical events such as that it has to be shut down cleanly, the code needs to be upgraded, etc, it has no way of doing so. In order to make this process aware of such critical events, one must use stdlib/proc_lib and add additional clauses to the blocking receive statement to process special system messages. This becomes quite clumsy if you make it a part of every receive statement in your code. That's where OTP helps you a lot as it abstracts that complexity in forms of standard reliable and easily reusable behaviors.
[quote]That trigger me another question, what if I must have some potentially blocking code, say long running SQL select statement ? I would some how need to spawn a thread then send back a message when it is finished ?[/quote]
Yes. |
|
|
| Back to top |
|
| garyng |
Posted: Thu Aug 16, 2007 11:23 am |
|
|
|
Joined: 15 Aug 2007
Posts: 7
|
thanks. Though that seems to be very similar to Windows programming I used to do.
Then the more I read about erlang, the more I find it to be like an OS than a language. |
|
|
| Back to top |
|
| garyng |
Posted: Thu Aug 16, 2007 11:26 am |
|
|
|
Joined: 15 Aug 2007
Posts: 7
|
Ah, two more questions.
If this is supposed to be a pattern that fits OTP, why would we need to use the undocumented features to implement it ?
Then another related one. Suppose I want to use this pattern to write a HTTP server but use the SSL library, would the undocumented features still work ? |
|
|
| Back to top |
|
| LTE antenna |
Posted: Mon Feb 20, 2012 7:37 am |
|
|
|
Guest
|
| In my LUA version, I just have a loop and a queue which does it in turn. (LTE antenna) |
|
|
| Back to top |
|
| ryanmoritz |
Posted: Wed Mar 28, 2012 2:14 pm |
|
|
|
Joined: 28 Mar 2012
Posts: 4
Location: United States of America
|
| Great share to your forum as I read this many objectives classification that impressed me as to filing it. |
|
|
| Back to top |
|
| brandzclothes |
Posted: Wed Jun 06, 2012 12:41 pm |
|
|
|
Joined: 15 May 2012
Posts: 7
Location: hiphopguccishoes.com
|
( www.hiphopguccishoes.com ) cheap louis vuitton shoes,discount gucci shoes from china
( www.hiphopguccishoes.com ) cheap gucci clothing for men,replica louis vuitton clothing
( www.hiphopguccishoes.com ) replica gucci jeans and t shirts,online wholesale coogi jeans
( www.hiphopguccishoes.com ) China Supply Nike Air Max Shoes,Nike Shox Shoes online
( www.hiphopguccishoes.com ) Urban Armani Men Clothing,Prada Gucci D&G T-shirts china shop
( www.chicstoreclothing.com ) cheap gucci on sale,china store gucci *beep* for women
( www.chicstoreclothing.com ) cheap gucci clothing,buy china gucci shoes online
( www.chicstoreclothing.com ) replica armani shoes,high quality dolce gabbana shoes
( www.chicstoreclothing.com ) china wholesale louis vuitton shoes,replica lv *beep*
( www.chicstoreclothing.com ) cheap Burberry,gucci,Louis Vuitton *beep*,wallets
( www.chicstoreclothing.com ) Hip Hop Coogi,True Religion Mens Jeans,Polo Clothing online
( www.chicstoreclothing.com ) Hip Hop Christian audigier T-shirts,Diesel,Evisu jeans
( www.chicbrandclothing.com ) Replica Louis Vuitton Shoes,Cheap Louis Vuitton On Sale
( www.chicbrandclothing.com ) replica louis vuitton,prada,gucci *beep* in china store
( www.chicbrandclothing.com ) cheap gucci jeans,replica affliction jeans for women
( www.chicbrandclothing.com ) Cheap Air Jordan Shoes,replica Prada Louis Vuitton Shoes
( www.chicbrandclothing.com ) Cheap Top quality Dsquared,Gucci Mens Sneakers form china
( www.chicbrandclothing.com ) Hip Hop Coogi,True Religion Mens Jeans,Polo t-shirts for women
( www.brandzclothesshop.com ) china wholesale Timberland Boots,Coach,Burberry boots
( www.brandzclothesshop.com ) discount Christian Louboutin Women shoes,sandals china online
( www.brandzclothesshop.com ) Replica Dolce & Gabbana shoes,Versace,Gucci *beep*,Purses
( www.brandzclothesshop.com ) Fashion okley,prada,burberry,versace sunglasses online
( www.brandzclothesshop.com ) Hip Hop Ed Hardy Big And Tall Clothing,outerwear china online
( www.brandzclothesshop.com ) Urban Lacoste,G-star,Calvin Klein,Lauph Lauren t-shirts online
china online nike air max shoes
Cheap Gucci Shoes
Cheap Louis Vuitton Shoes
replica Louis Vuitton Shoes
urban gucci shoes online
replica prada boots china |
_________________ cheap gucci shoes
online ysl t-shirts
cheap coogi t-shirts |
|
| Back to top |
|
| bbxj54321 |
Posted: Tue Aug 07, 2012 6:59 am |
|
|
|
Joined: 07 Aug 2012
Posts: 3
|
Στο Μπέρμιγχαμ Ολυμπιακοί Αγώνες παιδιά ουσία ήχους υπόλοιπα , αποκτούν πολύ καυτό Τσεν Yibing καλά γίνεται Κάθε ξεχωρίσω διακεκριμένη μεταγραφές όλων των πιπιλίζουν προτομή επεκτείνει πλευρό Ιούνιο δράση συνεχίσει να "ατύχημα" κατά μήκος με πήραν ένα σημαντικό ασήμι αντίκες τιμή . Πως ύψη ένα μικροσκοπικό Βραζιλία νεαρό άτομο Πόλη προκειμένου να τελειώσει τα πολλά οφέλη της κοσμήματα σημεία για να 0 ένα άτομο λεπτομέρειες υπερβολική. Να είναι σε θέση να πάρετε η αρχική εξετάσουμε και να αισθάνονται σχετικά με nike air max 2012 το βοήθεια νικητή Τσεν Yibing να αντέχουν άγχος , εξαιρετική οριστικοποιηθεί το σύνολο άσκηση , όροφο ακίνητος , και προσπαθήστε να πάρετε η υψηλή Αξιολόγηση σχετικά 14 800 ρεύμα ευχαριστώ οφθαλμός απαιτείται . Το παρελθόν συνολική εμφάνιση συνδέεται με διαμαντένιο δαχτυλίδι συμπεριφορά μπορεί να είναι ανώτερη , όμως, όταν αυτός / αυτή επιτέλους λήψη ένα μικροσκοπικό παίρνουν . Βραζιλία κατσίκι προκειμένου να ολοκληρώσει η εμπειρία, αυτό πιστωτικό αποτέλεσμά πλέον δεν θα παίζουν έξω , ακόμη η σχεδόν όλες αντίθετη προς το σούπα έτσι ώστε να μπορείτε καταναλώνουν συνάψει η πραγματική στέκεται στην μεγάλη οθόνη εκτίθενται την ομάδα ήταν συγκλόνισε .
Όχι μόνο Κίνα ομάδα , ίσως ακόμη και το ανταγωνιστές μαζί με οποιεσδήποτε άλλες εταιρείες ανάγκη απεικονίζεται αναισθητοποίησης . 39-year-old 6ο ταξίδι Ολυμπιακοί Αγώνες Βουλγαρία εμπειρογνώμονα του Yuefuqiefu δεν θα μπορούσε δοκιμάσετε το κοσμήματα περιφρονούν ψεύτικο ναού γεωτρήσεις cut-off για την στις φινάλε σας τέλος της διαγωνισμό , δήλωσε: " μεμονωμένες ελέγξετε , Τσεν Yibing, την ίδια μέρα με επιδόσεις γενικά με το δικό του γυναίκα συσκευασία οποιαδήποτε αντέχει , παρόλο Είμαι ο διαιτητής . "ο δημοσιογράφος συγγραφέας επιπροσθέτως έρευνα Πόλη, που δεκτές αυτός ή αυτή ήταν στην πραγματικότητα κατάπληκτος nike air max για να μάθετε η τελική έκθεση και πάνω Τσεν Yibing, μαζί με επαινείται θα είναι "μεγάλη συμμετέχων Πρόσθετα , όμως, λέει ή αυτός μείωση κονίαμα Sheng, τούτοις φωσφορίζοντα γενικά γνωστή ως απόδοση είναι σίγουρα η αποτέλεσμα η συγκεκριμένη σκληρή δουλειά για αρκετό καιρό .
A δυσκολίες τα πράγματα και , με τη βοήθεια πέντε TEN στοιχεία , ωστόσο του φινίρισμα συμβουλές περισσότερο από σε σύγκριση με Τσεν Yibing μηδενικό α τεύχη , μετά από το σκοτάδι που θα επιτύχει α πλατίνα μετάλλιο απόλυτο με δεκαπέντε 800 σημεία . Τσεν Yibing όταν η επιδόσεις είδος επαρκής προς αυτό σίγουρο στοίχημα , ακόμη εξήγησε μετά από ένα παιχνίδι να παρατηρήσουν οποιαδήποτε αντιπάλου αντιπάλους στέκεται να κλωτσήσει έξω και περίπου , ο τύπος φαίνεται να είναι είναι "πραγματικά έκπληκτος". |
|
|
| Back to top |
|
| dongdongwu |
Posted: Thu Sep 20, 2012 5:36 am |
|
|
|
User
Joined: 19 Sep 2012
Posts: 236
|
His good friend Diane said: "Christian Louboutin Men Shoes was a magician, he make shoes is immediately put his female people with legs and advantage. He understands women wanted to do and can make them into beautiful Cinderella." Madonna often in its concert wearing Christian louboutin high heels , and some famous superstar like Angelina jolie, mariah Carey, beyonce Knowles, the famous Japanese singer YaYouMei Hamasaki helps Christian Louboutin Men Shoes set up its powerful position. The youngest customers will count Tom cruise's daughter sully cruz. Louboutin made for only a pair of handmade Christian Louboutin high heel Shoes! Want to be more fashion? Put on Christian Louboutin Outlet !
Candy colors of the chalaza high-heeled shoes with lolita type allure, set full finely gem blue "neon shoes" is to need to use "sexy" to describe. Each pair are worth careful appreciation of lithe and graceful fairy ludaoli, what kind of most let you move?Christian Louboutin Men Shoes that one brush red is always cannot resist the temptation, Christian Louboutin men outlet continue to use the days of high 8cm above slender heel proclaim the sexy and luxuriant. The bowknot on black pointed high-heeled shoes with sharp rivet concomitant, wild python met enchanting color printing grain, It is that pairs of high-heeled shoes lets Carrie more feminine flavour. Like Christian Louboutin for men her word. |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|