Your SlideShare is downloading. ×
0
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
并发模型介绍
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

并发模型介绍

1,139

Published on

From Beijing Perl Workshop 2011 http://conference.perlchina.org/bjpw2011/

From Beijing Perl Workshop 2011 http://conference.perlchina.org/bjpw2011/

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,139
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Achilles Xuformalin14@gmail.com
  • 2. Contents•••••••
  • 3. • I/O CPU / CPU• I/O CPU• /
  • 4. •• • •
  • 5. • linux win•• top cpu
  • 6. my @urllist = read_list();my @pids;for my $url (@urllist) { my $pid = fork(); if ($pid == 0) { print get($url); exit; } elsif ($pid > 0) { push @pids, $pid; # ID }}waitpid($_, ...) for @pids; ## do other nonconcurrent jobs
  • 7. my @pids;for ( 1 .. 20) { my $pid = fork; if ($pid == 0) { while (1) { my $task = lock_and_get_task(); do_task($task); sleep 1; } exit; } elsif ($pid > 0) { push @pids, $pid; }}waitpid($_, ...) for @pids;
  • 8. •• top cpu• perl 5.8.5 perl 5.8.8 LWP
  • 9. use threads;sub load_url { print get($_[0]);}my @urllist = read_url_list();my @tids;for my $url (@urllist) { my $tid = threads->create(&load_url, $url); push @tids, $tid; # ID}$_->join for @tids; # waitpid# do other things
  • 10. use threads;use threads::shared;my @queue : shared;for (1 .. 6) { threads->create( sub { while (1) { my $task; { lock @queue; $task = shift @queue; } do_task($task); threads::sleep(1); } }}while (1) { generate_task(@queue); threads::sleep(1); }
  • 11. java.lang.Thread• linux windows•
  • 12. • C Python GIL• Coro Coroutines•
  • 13. Coro• I/O CPU• cede CPU• Perl6 async
  • 14. Corouse Coro;async { # some asynchronous thread of execution print "2n"; cede; # yield back to main print "4n";};print "1n";cede; # yield to coroprint "3n";cede; # and again
  • 15. • I/O•••
  • 16. • select• poll select• epoll I/O• I/O sendfile
  • 17. • POE• Twisted• AnyEvent• Java NIO
  • 18. POE•• yield• Session• $heap•
  • 19. POE sub handler_increment { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Session ", $session->ID, "counted to ", ++$heap->{count}, ".n"; $kernel->yield(increment) if$heap->{count} < 10; }
  • 20. Twisted••• POE N•• dns connect send request got first byte.... hook•
  • 21. Twistedd = conect_to_server()d.addCallback(login_user)d.addErrback(reconnect_to_server)reactor.run()
  • 22. AnyEvent• libevent EV••• Coro POE
  • 23. Java NIO• linux windows• Channel
  • 24. • Squid 2.x• Apache• Nginx
  • 25. Squid 2.x•• sendfile•• COSS•
  • 26. Apache••• php
  • 27. Nginx•• epoll kqueue sendfile writev••
  • 28. • Questions

×