SlideShare a Scribd company logo
‹#›
‹#›
‹#›
‹#›
‹#›
‹#›
‹#›
‹#›
‹#›
‹#›
6
                                   Worker	
  
                                   Thread

                                   Worker	
  
                                   Thread           Web Container
                                   Worker	
  
                                                    HTTP Engine
                                   Thread

                                   Worker	
  
                                                         VS Select
                                   Thread

            Acceptor	
             Worker	
         NSAPI Engine
            Thread                 Thread
                               4                5
            Acceptor	
             Worker	
         …
            Thread                 Thread

    1   2                  3                7


                                                        KeepAlive	
  
                                                         Thread
                                                        KeepAlive	
  
                                                         Thread
9                                               8




                                                                        ‹#›
                 	
	
                                            	
                    	



       B	
                       B	
  
               Thread-­‐1	
                        Thread-­‐1	
  

       B	
                       B	
  
               Thread-­‐2	
                        Thread-­‐2	
  

       B	
                       B	
  
               Thread-­‐3	
                        Thread-­‐3	
  




                                                                         ‹#›
‹#›
no9fy

no9fy




        ‹#›
Selector selector = Selector.open();!
ServerSocketChannel serverChannel = ServerSocketChannel.open();!
serverChannel.configureBlocking(false);//                   !
serverChannel.socket().bind(new InetSocketAddress(9090));!
serverChannel.register(selector, SelectionKey.OP_ACCEPT);!
while (selector.select() > 0) {!
    for (Iterator it = selector.selectedKeys().iterator();
it.hasNext();) {!
       SelectionKey key = (SelectionKey) it.next();!
       it.remove();!
       if (key.isAcceptable()) {!
           ServerSocketChannel serverChannel =!
               (ServerSocketChannel) key.channel();!
           SocketChannel channel = serverChannel.accept();!
           channel.configureBlocking(false);!
           channel.register(selector, SelectionKey.OP_READ);!

                                                             ‹#›
SocketChannel channel = serverChannel.accept();!



AsynchronousServerSocketChannel server =
AsynchronousServerSocketChannel.open().bind(9900);!
Future<AsynchronousSocketChannel> acceptFuture = server.accept
();!
AsynchronousSocketChannel worker = future.get();!
//AsynchronousSocketChannel worker = future.get(10,
TimeUnit.SECONDS); //                             !




                                                             ‹#›
‹#›
‹#›
GlassFish glassfish = GlassFishRuntime.bootstrap().!
     !     !     !     !     !     !     !newGlassFish();!
glassfish.start();!
!

CommandRunner commandRunner = glassfish.getService
(CommandRunner.class);!
CommandResult commandResult = commandRunner.run("create-http-
listener", "--listenerport=9090", "--listeneraddress=0.0.0.0",
"--defaultvs=server", "my-http-listener");!
!

Deployer deployer = glassfish.getDeployer();!
deployer.deploy(new File(“HelloWorldWeb-GA.war"));!




                                                             ‹#›
public class HelloWorldAdapter extends GrizzlyAdapter {!
    @Override!
    public void service(GrizzlyRequest request, GrizzlyResponse
response) {!
        try {!
             response.getWriter().println("HelloWorld");!
        } catch (IOException ex) {!
             ex.printStackTrace();!
        }}!

<adapters>!
    <adapter context-root="/helloworld" class-
name="co.jp.oracle.http.HelloWorldAdapter"/>!
</adapters>!

> asadmin deploy helloworld.jar


                                                             ‹#›
GrizzlyWebServer gws = new GrizzlyWebServer(8080, "no static
content");!
!
ServletAdapter simpleServletAdapter = new ServletAdapter();!
simpleServletAdapter.setContextPath("/hello");!
simpleServletAdapter.setServletInstance(new MyServlet());!
gws.addGrizzlyAdapter(simpleServletAdapter, new String[]{"/
hello"});!
!
gws.start();!




                                                               ‹#›
‹#›
-Dcom.sun.grizzly.displayConfiguration = true!


Grizzly running on Darwin - 10.8.0 under JDK version: 1.7.0-internal -
Oracle Corporation !
         port: 4848!
         Thread Pool:
com.sun.enterprise.v3.services.impl.monitor.MonitorableThreadPool@7e8e
68bd, port=4848!
         Read Selector: -1!
         ByteBuffer size: 8192 !
         maxHttpHeaderSize: 8192!
         sendBufferSize: 8192!
         maxKeepAliveRequests: 250!
         keepAliveTimeoutInSeconds: 30 !
         Static File Cache enabled: false!
                                                                     ‹#›
         Adapter : com.sun.enterprise.v3.services.impl.ContainerMapper !
         Asynchronous Request Processing enabled: false|#]!
-­‐Dcom.sun.grizzly.enableSnoop=true!



[#|2011-­‐09-­‐01T22:00:39.319+0900|INFO|glassfish3.1.1|
com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=67;_ThreadName=Thread-­‐2;|GRIZZLY0020:	
  
SocketChannel	
  headers	
  java.nio.channels.SocketChannel[connected	
  local=/127.0.0.1:4848	
  remote=/
127.0.0.1:55379]	
  are:	
  	
  
===	
  MimeHeaders	
  ===	
  
host	
  =	
  127.0.0.1:4848	
  
user-­‐agent	
  =	
  Mozilla/5.0	
  (Macintosh;	
  Intel	
  Mac	
  OS	
  X	
  10.6;	
  rv:6.0.1)	
  Gecko/20100101	
  Firefox/6.0.1	
  
accept	
  =	
  text/html,applica9on/xhtml+xml,applica9on/xml;q=0.9,*/*;q=0.8	
  
accept-­‐language	
  =	
  ja,en;q=0.7,en-­‐us;q=0.3	
  
accept-­‐encoding	
  =	
  gzip,	
  deflate	
  
accept-­‐charset	
  =	
  Shil_JIS,un-­‐8;q=0.7,*;q=0.7	
  



                                                                                                                                      ‹#›
-client!
-Xmx512m!


-server !
-Xmx3500m -Xms3500m -Xss128k !
-XX:+AggressiveHeap !
-XX:+DisableExplicitGC!




                                 ‹#›
‹#›

More Related Content

Grizzly1.9.3x

  • 11. 6 Worker   Thread Worker   Thread Web Container Worker   HTTP Engine Thread Worker   VS Select Thread Acceptor   Worker   NSAPI Engine Thread Thread 4 5 Acceptor   Worker   … Thread Thread 1 2 3 7 KeepAlive   Thread KeepAlive   Thread 9 8 ‹#›
  • 12.     B   B   Thread-­‐1   Thread-­‐1   B   B   Thread-­‐2   Thread-­‐2   B   B   Thread-­‐3   Thread-­‐3   ‹#›
  • 14. no9fy no9fy ‹#›
  • 15. Selector selector = Selector.open();! ServerSocketChannel serverChannel = ServerSocketChannel.open();! serverChannel.configureBlocking(false);// ! serverChannel.socket().bind(new InetSocketAddress(9090));! serverChannel.register(selector, SelectionKey.OP_ACCEPT);! while (selector.select() > 0) {!     for (Iterator it = selector.selectedKeys().iterator(); it.hasNext();) {!        SelectionKey key = (SelectionKey) it.next();!        it.remove();!        if (key.isAcceptable()) {!            ServerSocketChannel serverChannel =! (ServerSocketChannel) key.channel();! SocketChannel channel = serverChannel.accept();! channel.configureBlocking(false);!            channel.register(selector, SelectionKey.OP_READ);! ‹#›
  • 16. SocketChannel channel = serverChannel.accept();! AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open().bind(9900);! Future<AsynchronousSocketChannel> acceptFuture = server.accept ();! AsynchronousSocketChannel worker = future.get();! //AsynchronousSocketChannel worker = future.get(10, TimeUnit.SECONDS); // ! ‹#›
  • 19. GlassFish glassfish = GlassFishRuntime.bootstrap().! ! ! ! ! ! ! !newGlassFish();! glassfish.start();! ! CommandRunner commandRunner = glassfish.getService (CommandRunner.class);! CommandResult commandResult = commandRunner.run("create-http- listener", "--listenerport=9090", "--listeneraddress=0.0.0.0", "--defaultvs=server", "my-http-listener");! ! Deployer deployer = glassfish.getDeployer();! deployer.deploy(new File(“HelloWorldWeb-GA.war"));! ‹#›
  • 20. public class HelloWorldAdapter extends GrizzlyAdapter {! @Override! public void service(GrizzlyRequest request, GrizzlyResponse response) {! try {! response.getWriter().println("HelloWorld");! } catch (IOException ex) {! ex.printStackTrace();! }}! <adapters>! <adapter context-root="/helloworld" class- name="co.jp.oracle.http.HelloWorldAdapter"/>! </adapters>! > asadmin deploy helloworld.jar ‹#›
  • 21. GrizzlyWebServer gws = new GrizzlyWebServer(8080, "no static content");! ! ServletAdapter simpleServletAdapter = new ServletAdapter();! simpleServletAdapter.setContextPath("/hello");! simpleServletAdapter.setServletInstance(new MyServlet());! gws.addGrizzlyAdapter(simpleServletAdapter, new String[]{"/ hello"});! ! gws.start();! ‹#›
  • 23. -Dcom.sun.grizzly.displayConfiguration = true! Grizzly running on Darwin - 10.8.0 under JDK version: 1.7.0-internal - Oracle Corporation ! port: 4848! Thread Pool: com.sun.enterprise.v3.services.impl.monitor.MonitorableThreadPool@7e8e 68bd, port=4848! Read Selector: -1! ByteBuffer size: 8192 ! maxHttpHeaderSize: 8192! sendBufferSize: 8192! maxKeepAliveRequests: 250! keepAliveTimeoutInSeconds: 30 ! Static File Cache enabled: false! ‹#› Adapter : com.sun.enterprise.v3.services.impl.ContainerMapper ! Asynchronous Request Processing enabled: false|#]!
  • 24. -­‐Dcom.sun.grizzly.enableSnoop=true! [#|2011-­‐09-­‐01T22:00:39.319+0900|INFO|glassfish3.1.1| com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=67;_ThreadName=Thread-­‐2;|GRIZZLY0020:   SocketChannel  headers  java.nio.channels.SocketChannel[connected  local=/127.0.0.1:4848  remote=/ 127.0.0.1:55379]  are:     ===  MimeHeaders  ===   host  =  127.0.0.1:4848   user-­‐agent  =  Mozilla/5.0  (Macintosh;  Intel  Mac  OS  X  10.6;  rv:6.0.1)  Gecko/20100101  Firefox/6.0.1   accept  =  text/html,applica9on/xhtml+xml,applica9on/xml;q=0.9,*/*;q=0.8   accept-­‐language  =  ja,en;q=0.7,en-­‐us;q=0.3   accept-­‐encoding  =  gzip,  deflate   accept-­‐charset  =  Shil_JIS,un-­‐8;q=0.7,*;q=0.7   ‹#›
  • 25. -client! -Xmx512m! -server ! -Xmx3500m -Xms3500m -Xss128k ! -XX:+AggressiveHeap ! -XX:+DisableExplicitGC! ‹#›