Tomcat 6: Evolving our server

3,088 views

Published on

Elecnor Deimos Tomcat 6 slideshare
Debugging
Valves
Apache
Load Balancing
Clustering
Monitoring

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

No Downloads
Views
Total views
3,088
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Tomcat 6: Evolving our server

  1. 1. Tomcat 6: Evolving our service Preface Debugging Valves Apache WS + Tomcat Load Balancing Clustering Monitoring
  2. 2. Introducing our project <ul><li>Mobile based online marketing project </li></ul><ul><li>J2EE technology: scalable and robust. To serve applications we need Tomcat. </li></ul><ul><li>Ubuntu server under three enviroments: develop, preproduction and production. </li></ul><ul><li>Servers with external provider. </li></ul><ul><li>Mobile Web and Proxy in the same app. </li></ul>
  3. 3. Architecture Web Proxy Backend MySQL Tomcat Server Client Server Shared Database Server
  4. 4. Challenge: Testing integration <ul><li>Qustodian Backend needs a fixed URL to connect. </li></ul><ul><li>We develop the project with IDE and debugger. </li></ul><ul><li>We can't emulate client conection to our system. </li></ul><ul><li>Conclusion: Dificult to locally debug. </li></ul>
  5. 5. Solution: Remote debugging <ul><li>Tomcat has a connector that allows to debugger to plug in to the server. </li></ul><ul><li>Using Java Platform Debugger Architecture (JDPA)and Java Debug Wire Protocol (JDWP) </li></ul><ul><li>Configuring Tomcat in catalina.sh to start in debug mode adding to CATALINA_OPTS variable with export. </li></ul><ul><li>Another script to invoke Tomcat with this options to avoid editing everytime. </li></ul><ul><li>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000 </li></ul>
  6. 6. Remote debugging <ul><li>In NetBeans you can start remote debugger in these buttons: </li></ul><ul><li>And configure it with: </li></ul>
  7. 7. Challenge: Following server request <ul><li>Service starts being bigger. </li></ul><ul><li>Mobile applications connects to Proxy REST API. </li></ul><ul><li>Backend request to Proxy. </li></ul><ul><li>Is a good practice to follow users activity. </li></ul><ul><li>In Apache Web Server we have an access log. </li></ul><ul><li>Easy to detect bad requests or attacks. </li></ul>
  8. 8. Previous concept: Valves <ul><li>Valves are Tomcat components which is inserted into request processing pipeline for the associated Catalina container. </li></ul><ul><li>Several applications in Tomcat: </li></ul><ul><ul><li>Access Log </li></ul></ul><ul><ul><li>Remote Address or Host Filter </li></ul></ul><ul><ul><li>Authentication </li></ul></ul><ul><ul><li>More ... </li></ul></ul>
  9. 9. Solution: AccessLogValve <ul><li>We only need to uncomment in server.xml the line: </li></ul><ul><li><Valve className=&quot;org.apache.catalina.valves.AccessLogValve&quot; directory=&quot;logs&quot; prefix=&quot;localhost_access_log.&quot; suffix=&quot;.txt&quot; pattern=&quot;common&quot; resolveHosts=&quot;false&quot;/> </li></ul><ul><li>The common pattern show log entries in this way: </li></ul><ul><ul><li>REMOTE_HOST - REMOTE_USER DATETIME &quot;REQUEST_FIRST_LINE&quot; HTTP_STATUS_CODE BYTES_SENT </li></ul></ul><ul><li>There are others log patterns and options to configure, as conditional logging can be found here . </li></ul>
  10. 10. Access Log applications <ul><li>There are many software handling the access log to show it in graphical mode improving its analysis. </li></ul><ul><li>Some examples are: </li></ul><ul><ul><li>http://www.weblogexpert.com/ </li></ul></ul><ul><ul><li>http://www.hping.org/visitors/ </li></ul></ul>
  11. 11. Challenge: Hide pass in request <ul><li>Mobile clients make the request to login. </li></ul><ul><li>Avoid storing passwords in the log file. </li></ul><ul><li>Hide password string from request under * characters. </li></ul>http://m.qustodian.com/api/users/login?pass= **** &device_platform=200
  12. 12. Solution: Extending LogValve
  13. 13. Challenge: Better performance <ul><li>In Qustodian, user activity started growing soon. </li></ul><ul><li>We had a main critical operation: publishing campaigns to users. </li></ul><ul><li>Campaigns to 4000 users approx. </li></ul><ul><li>Too many connections: threads in heap memory and DB connections </li></ul>
  14. 14. Solution: Improve server <ul><li>We asked for RAM memory </li></ul><ul><li>Updated OpenJDK to last Oracle JVM. </li></ul><ul><li>Updated the Apache Tomcat version </li></ul><ul><li>Modified Tomcat start with new memory params </li></ul>
  15. 15. Challenge: High Availability <ul><li>Shorten deployment time in production. </li></ul><ul><li>Minimize impact of server down to users. </li></ul>
  16. 16. Solution: Load Balancing <ul><li>High Availability performance and scalability. </li></ul><ul><li>Ask for two or more nodes with Tomcat. </li></ul><ul><li>Apache Web Server as balancer component. </li></ul><ul><li>Mantain session persistence across the nodes </li></ul>
  17. 17. Apache and Tomcat <ul><li>Apache Web Server redirecting traffic to nodes. </li></ul><ul><li>Apache schedule the request with algorithms. </li></ul><ul><li>Sticky sessions as solution to avoid session lost. </li></ul><ul><li>Using mod_jk or mod_proxy connectors. </li></ul>
  18. 18. Apache as balancer with mod_proxy <ul><li>Copy the modules to mods-enabled directory </li></ul><ul><li>proxy_ajp.load -> ../mods-available/proxy_ajp.load </li></ul><ul><li>proxy.load -> ../mods-available/proxy.load </li></ul><ul><li>proxy.conf -> ../mods-available/proxy.conf </li></ul><ul><li>proxy_balancer.load -> ../mods-available/proxy_balancer.load </li></ul><ul><li>Configure proxy_balancer.conf </li></ul><ul><li><Proxy balancer://mycluster> </li></ul><ul><li>BalancerMember http://192.168.1.50:8080 </li></ul><ul><li>BalancerMember http://192.168.1.51:8080 </li></ul><ul><li></Proxy> </li></ul><ul><li>ProxyPass /test balancer://mycluster </li></ul>
  19. 19. BrightBox has a balancer <ul><li>BrightBox provides a Load Balancer highly configurable with limitations: </li></ul><ul><ul><li>Depends on IP:PORT </li></ul></ul><ul><ul><li>Least Connection : scheduler which means connections are allocated to the server with the least number of connections </li></ul></ul><ul><ul><li>5 min Sticky Session </li></ul></ul><ul><ul><li>Server can not access to balancer IP </li></ul></ul><ul><li>We have a fast solution and more problems ... </li></ul>
  20. 20. Architecture Web Proxy Backend MySQL Tomcat Server Client Server Database Server Web Proxy Tomcat Server Web Proxy Tomcat Server B 2 1 Balancer
  21. 21. Challenge:Keeping session <ul><li>Mobiles usually changes IP each request, so we lose session. </li></ul><ul><li>If server goes down, you need to login again in other. </li></ul>
  22. 22. Solution: Session Replication <ul><li>Session replication in Tomcat cluster. </li></ul><ul><li>Two algorithm: </li></ul><ul><ul><li>SimpleTcpReplicationManager </li></ul></ul><ul><ul><li>DeltaManager </li></ul></ul><ul><li>Communication over: </li></ul><ul><ul><li>IP Multicast </li></ul></ul><ul><ul><li>IP Sockets </li></ul></ul><ul><li>Session-state persistence: </li></ul><ul><ul><li>In memory (SimpleTcpCluster) </li></ul></ul><ul><ul><li>Database persistence (JDBCManager) </li></ul></ul><ul><ul><li>File-based persistence (PersistenceManager) </li></ul></ul>
  23. 23. IP Sockets in-memory replication <ul><li>Application must be “ distributable ” in web.xml </li></ul><ul><li>Stored objects in session must be serializable . </li></ul><ul><li>All session attributes are replicated for each HTTP Request </li></ul><ul><li>Valves to filter the replication. </li></ul>
  24. 24. Architecture Web Proxy Backend MySQL Tomcat Server Client Server Database Server Web Proxy Tomcat Server Web Proxy Tomcat Server B 2 1 Balancer Session Replication
  25. 25. Challenge: Monitoring Tomcat <ul><li>Server activity </li></ul><ul><li>Show request time </li></ul><ul><li>Watch server load </li></ul><ul><li>Alerts if server goes down </li></ul>
  26. 26. Solution:Three services <ul><li>Monit – installed in server, to trigger actions under conditions </li></ul><ul><li>NewRelic – installed in tomcat, to monitoring application and server memory, request … </li></ul><ul><li>Pingdom – installed in iPhone, service that alerts you if server goes down. </li></ul>
  27. 27. Pingdom
  28. 28. Question time

×