简体   繁体   English

构建一个大型Java应用程序,您将使用什么堆栈?

[英]building a high scale java app, what stack would you use?

if you needed to build a highly scalable web application using java, what framework would you use and why? 如果您需要使用Java构建高度可扩展的Web应用程序,那么将使用什么框架,为什么?

I'm just reading thinking-in-java, head first servlets and manning's spring framework book, but really I want to focus on highly scalable architectures etc. 我只是在阅读Java思考,首先介绍servlet和Manning的spring框架书,但实际上我想专注于高度可扩展的体系结构等。

would you use tomcat, hibernate, ehcache? 您会使用tomcat,hibernate,ehcache吗?

(just assume you have to design for scale, not looking for the 'worry about it when you get traffic type responses) (仅假设您必须针对规模进行设计,而不是在获得流量类型响应时寻找“后顾之忧”)

The answer depends on what we mean by "scalable". 答案取决于我们所说的“可扩展”。 A lot depends on your application, not on the framework you choose to implement it with. 很大程度上取决于您的应用程序,而不取决于您选择用来实现该程序的框架。

No matter what framework you choose, the fact is that the hardware you deploy it on will have an upper limit on the number of simultaneous requests it'll be able to handle. 无论选择哪种框架,事实都是部署它的硬件对它能够处理的并发请求数量有一个上限。 If you want to handle more traffic, you'll have to throw more hardware at it and include load balancing, etc. 如果要处理更多的流量,则必须向其扔更多的硬件,并包括负载平衡等。

The part that's pertinent in that case has to do with shared state. 在这种情况下,与之相关的部分与共享状态有关。 If you have a lot of shared state, you'll have to make sure that it's thread safe, "sticky" when it needs to be, replicated throughout a cluster, etc. All that has to do with the app server you deploy it to and the way you design your app, not the framework. 如果您有很多共享状态,则必须确保它是线程安全的,在需要时是“粘性”的,在整个集群中复制等。所有与您将其部署到的应用服务器有关以及您设计应用程序的方式,而不是框架。

Tomcat's not a "framework", it's a servlet/JSP engine. Tomcat不是“框架”,而是servlet / JSP引擎。 It's got clustering capabilities, but so do most other Java EE app servers. 它具有集群功能,但其他大多数Java EE应用服务器也具有集群功能。 You can use Tomcat if you've already chosen Spring, because it implies that you don't have EJBs. 如果您已经选择了Spring,则可以使用Tomcat,因为这意味着您没有EJB。 Jetty, Resin, WebLogic, JBOSS, Glassfish - any of them will do. 码头,树脂,WebLogic,JBOSS,Glassfish-他们中的任何一个都可以。

Spring is a good choice if you already know it well. 如果您已经非常了解春天,那么它是一个不错的选择。 I think following the Spring idiom will make it more likely that your app is layered and architecturally sound, but that's not the deciding factor when it comes to scalability. 我认为,遵循Spring习惯用法将使您的应用更有可能是分层的并且在体系结构上合理,但这并不是可伸缩性的决定因素。

Hibernate will make your development life easier, but the scalability of your database depends a great deal on the schema, indexes, etc. Hibernate isn't a guarantee. Hibernate将使您的开发工作更加轻松,但是数据库的可伸缩性在很大程度上取决于架构,索引等。Hibernate并不能保证。

"Scalable" is one of those catch-all terms (like "lightweight") that is easy to toss off but encompasses many considerations. “可伸缩”是易于理解但包含许多考虑因素的广泛使用的术语之一(例如“轻量级”)。 I'm not sure that a simple choice of framework will solve the issue once and for all. 我不确定简单选择框架会一劳永逸地解决问题。

I would check out Apache Mina . 我会检查Apache Mina From the home page: 从主页:

Apache MINA is a network application framework which helps users develop high performance and high scalability network applications easily. Apache MINA是一个网络应用程序框架,可帮助用户轻松开发高性能和高可伸缩性的网络应用程序。 It provides an abstract · event-driven · asynchronous API over various transports such as TCP/IP and UDP/IP via Java NIO. 它通过Java NIO通过各种传输(例如TCP / IP和UDP / IP)提供了一个抽象的,事件驱动的异步API。

It has an HTTP engine AsyncWeb built on top of it. 它基于HTTP引擎AsyncWeb

A less radical suggestion (!) is Jetty - a servlet container geared towards performance and a small footprint. 一个不太激进的建议(!)是Jetty-一个面向性能和较小占用空间的servlet容器。

The two keywords I would mainly focus on are Asynchronous and Stateless . 我主要关注的两个关键字是异步无状态 Or at least "as stateless as possible: Of course you need state but maybe, instead of going for a full fledged RDBMS, have a look at document centered datastores. 或至少“尽可能地无状态:当然,您需要状态,但也许,而不是使用完整的RDBMS,请查看以文档为中心的数据存储。

Have a look at AKKA concerning async and CouchDB or MongoDB as datastores... 看看关于异步和CouchDBMongoDB作为数据存储的AKKA ...

Frameworks are more geared towards speeding up development, not performance. 框架更适合于加速开发,而不是性能。 There will be some overhead with any framework because of use cases it handles that you don't need. 任何框架都会有一些开销,因为它会处理不需要的用例。 Granted, the overhead may be low, and most frameworks will point you towards patterns that have been proven to scale, but those patterns can be used without the framework as well. 当然,开销可能很低,大多数框架将使您指向已被证明可以扩展的模式,但是这些模式也可以在没有框架的情况下使用。

So I would design your architecture assuming 'bare metal', ie pure servlets (yes, you could go even lower level, but I'm assuming you don't want to write your own http socket layer), straight JDBC, etc. Then go back and figure out which frameworks best fit your architecture, speed up your development, and don't add too much overhead. 因此,我将假设“裸机”(即纯servlet)来设计您的体系结构(是的,您甚至可以使用更低的级别,但我假设您不想编写自己的http套接字层),直接JDBC等。返回并找出最适合您的架构的框架,加快开发速度,并且不要增加太多开销。 Tomcat versus other containers, Hibernate versus other ORMs, Struts versus other web frameworks - none of that matters if you make the wrong decisions about the key performance bottlenecks. Tomcat与其他容器,Hibernate与其他ORM,Struts与其他Web框架-如果您对关键性能瓶颈做出错误决定,那么这些都不重要。

However, a better approach might be to choose a framework that optimizes for development time and then find the bottlenecks and address those as they occur. 但是,更好的方法可能是选择一个针对开发时间进行优化的框架,然后找到瓶颈并在出现瓶颈时加以解决。 Otherwise, you could spin your wheels optimizing prematurely for cases that never occur. 否则,您可能会过早地旋转车轮以应对从未发生的情况。 But that probably falls in the category of 'worry about it when you get traffic'. 但这可能属于“担心交通拥堵”类别。

All popular modern frameworks (and "stacks") are well-written and don't pose any threat to performance and scaling, if used correctly . 如果使用得当 ,所有流行的现代框架(和“堆栈”)都精心编写,不会对性能和扩展性构成任何威胁。 So focus on what stack will be best for your requirements, rather than starting with the scalability upfront. 因此,重点放在最适合您的需求的堆栈上,而不要从前期的可伸缩性开始。

If you have a particular requirement, then you can ask a question about it and get recommendations about what's best for handling it. 如果您有特定要求,则可以提出有关此问题的建议,并获得有关最佳处理方式的建议。

There is no framework that is magically going to make your web service scalable. 没有任何框架可以使您的Web服务具有可扩展性。

The key to scalability is replicating the functionality that is (or would otherwise be) a bottleneck. 可伸缩性的关键是复制曾经(或将是瓶颈)的功能。 If you are serious about making your service, you need to start with a good understanding of the characteristics of your application, and hence an idea of where the bottlenecks are likely to be: 如果您认真考虑提供服务,则需要对应用程序的特性有一个很好的了解,从而对可能出现瓶颈的地方有所了解:

  • Is it a read-only service or do user requests cause primary data to change? 它是只读服务,还是用户请求导致主要数据更改?
  • Do you have / need sessions, or is the system RESTful? 您是否有/需要会话,或者系统是否为RESTful?
  • Are the requests normal HTTP requests with HTML responses, or are you doing AJAX or callbacks or something. 请求是带有HTML响应的普通HTTP请求,还是正在执行AJAX或回调或其他操作。
  • Are user requests computation intensive, I/O intensive, rendering intensive? 用户请求是计算密集型,I / O密集型还是渲染密集型吗?
  • How big/complicated is your backend database? 后端数据库有多大/复杂?
  • What are the availability requirements? 可用性要求是什么?

Then you need to decide how scalable you want it to be. 然后,你需要决定你想如何可扩展的它是。 Do you need to support hundreds, thousands, millions of simultaneous users? 您需要支持成千上万的同时用户吗? (Different degrees of scalability require different architectures, and different implementation approaches.) (不同程度的可伸缩性需要不同的体系结构和不同的实现方法。)

Once you have figured these things out, then you decide whether there is an existing framework that can cope with the level traffic that you need to support. 一旦解决了这些问题,就可以确定是否有一个现有的框架可以应对您需要支持的级别流量。 If not, you need to design your own system architecture to be scalable in the problem areas. 如果不是,则需要设计自己的系统体系结构以在问题区域中进行扩展。

If you are able to work with a commercial system, then I'd suggest taking a look at Jazz Foundation at http://jazz.net . 如果您能够使用商业系统,那么建议您访问http://jazz.net上的Jazz Foundation。 It's the base for IBM Rational's new products. 它是IBM Rational新产品的基础。 The project is led by the guys that developed Eclipse within IBM before it was open-sourced. 该项目由在开源之前在IBM内部开发Eclipse的人员领导。 It has pluggable DB layer as well as supporting multiple App Servers. 它具有可插拔的数据库层,并支持多个App Server。 It's designed to handle clustering and multi-site type deployments. 它旨在处理集群和多站点类型部署。 It has nice capabilities like OAuth support and License management. 它具有不错的功能,例如OAuth支持和许可证管理。

As others already have replied scalability isn't about what framework you use. 正如其他人已经回答的那样,可伸缩性与您使用的框架无关。 Sure it is nice to squeeze out as much performance as possible from each node, but what you ideally want is that by adding another node you scale your app in a linear fashion. 当然,最好从每个节点中挤出尽可能多的性能,但是理想情况下,您需要添加另一个节点以线性方式扩展应用程序。

The application should be architected in distinct layers so it is possible to add more power to different layers of the application without a rewrite and also to add different layered caching. 应在不同的层中构建应用程序,以便可以在不重写的情况下为应用程序的不同层增加更多功能,并可以添加不同的分层缓存。 Caching is key to archive speed. 缓存是存档速度的关键。

One example of layers for a big webapp: 大型Web应用程序的图层示例:

  • Load balancers (TCP level) 负载均衡器(TCP级别)
  • Caching reverse proxies 缓存反向代理
  • CDN for static content CDN用于静态内容
  • Front end webservers 前端网络服务器
  • Appservers (business logic of the app) 应用服务器(应用的业务逻辑)
  • Persistent storage (RDBMS, key/value, document) 永久存储(RDBMS,键/值,文档)

In addition to the above: 除了上述内容:

Take a good look at JMS (Java Message Service). 充分了解JMS(Java消息服务)。 This is a much under rated technology. 这是一项远远低于额定的技术。 There are vendor solutions such as TibCo EMS, Oracle etc. But there are also free stacks such as Active MQ. 有供应商解决方案,例如TibCo EMS,Oracle等。但是也有免费堆栈,例如Active MQ。

JMS will allow you to build synch and asynch solutions using queues. JMS将允许您使用队列构建同步和异步解决方案。 You can choose to have persistent or non-persistent queues. 您可以选择具有持久或非持久队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您将使用哪些Java框架与Google App Engine合作? - What Java framework would you use with Google App Engine? 你会在App Engine中使用什么“未来”? - What would you use a “Future” for in App Engine? 您将在Java中使用什么部署脚本? - What would you use for deployment scripts in Java? appfuse vs roo - 你会用什么? - appfuse vs roo - what would you use 直接Java / Groovy与ETL工具(Talend / etc) - 您将使用哪些库? - Straight Java/Groovy versus ETL tool (Talend/etc) - what libraries would you use? 您是否会使用Laszlo为Java Web应用程序开发基于Flash的前端? - Would you use Laszlo to develop a Flash-based front end to a Java web app? 最佳的数据结构是什么? java的 - What would be the best data structure to use? java Java stackoverflowerror使用什么正确的堆栈大小? - Java stackoverflowerror what is the correct stack size to use? 为什么你会在java中使用BitSet而不是布尔数组(在Java中)? - Why would you use a BitSet in java as opposed to an array of booleans (in Java)? 你在MySQL / Hibernate中映射BigDecimal的类型是什么类型的? - What type would you map BigDecimal in Java/Hibernate in MySQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM