Rewrote becoming big and foreword
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 9e1111c · Browse files · 2 files·+72 added−56 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+72 added−56 removed
- other:+72 added−56 removed
Provenance
- Commit
bca1acf- Tree
b7887bd- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
9e1111c
2 files changed+72 added−56 removed
modified:docs/becomingbig.rst+60 added-40 removed
1 unmodified line2 3 Becoming Big4 ============5 6-Your application is becoming more and more complex? Flask is really not7-designed for large scale applications and does not attempt to do so, but8-that does not mean you picked the wrong tool in the first place.6+Your application is becoming more and more complex? If you suddenly7+realize that Flask does things in a way that does not work out for your8+application there are ways to deal with that.9 10 Flask is powered by Werkzeug and Jinja2, two libraries that are in use at11 a number of large websites out there and all Flask does is bring those12-two together. Being a microframework, Flask is literally a single file.13-What that means for large applications is that it's probably a good idea14-to take the code from Flask and put it into a new module within the15-applications and expand on that.12+two together. Being a microframework Flask does not do much more than13+combinding existing libraries - there is not a lot of code involved.14+What that means for large applications is that it's very easy to take the15+code from Flask and put it into a new module within the applications and16+expand on that.17 17-What Could Be Improved?18------------------------18+Flask is designed to be extended and modified in a couple of different19+ways:20 20-For instance it makes a lot of sense to change the way endpoints (the21-names of the functions / URL rules) are handled to also take the module22-name into account. Right now the function name is the URL name, but23-imagine you have a large application consisting of multiple components.24-In that case, it makes a lot of sense to use dotted names for the URL25-endpoints.21+- Subclassing. The majority of functionality can be changed by creating22+ a new subclass of the :class:`~flask.Flask` class and overriding23+ some methods.24 27-Here are some suggestions for how Flask can be modified to better 28-accommodate large-scale applications:25+- Flask extensions. For a lot of reusable functionality you can create26+ extensions.27 30-- get rid of the decorator function registering which causes a lot31- of troubles for applications that have circular dependencies. It32- also requires that the whole application is imported when the system33- initializes or certain URLs will not be available right away. A34- better solution would be to have one module with all URLs in there and35- specifying the target functions explicitly or by name and importing36- them when needed.37-- switch to explicit request object passing. This requires more typing38- (because you now have something to pass around) but it makes it a39- whole lot easier to debug hairy situations and to test the code.40-- integrate the `Babel`_ i18n package or `SQLAlchemy`_ directly into the41- core framework.28+- Forking. If nothing else works out you can just take the Flask29+ codebase at a given point and copy/paste it into your application30+ and change it. Flask is designed with that in mind and makes this31+ incredible easy. You just have to take the package and copy it32+ into your application's code and rename it (for example to33+ `framework`). Then you can start modifying the code in there.34 43-.. _Babel: http://babel.edgewall.org/44-.. _SQLAlchemy: http://www.sqlalchemy.org/35+Why consider Forking?36+---------------------37 46-Why does Flask not do all that by Default?47-------------------------------------------38+The majority of code of Flask is within Werkzeug and Jinja2. These39+libraries do the majority of the work. Flask is just the paste that glues40+those together. For every project there is the point where the underlying41+framework gets in the way (due to assumptions the original developers42+had). This is natural because if this would not be the case, the43+framework would be a very complex system to begin with which causes a44+steep learning curve and a lot of user frustration.45 49-There is a huge difference between a small application that only has to50-handle a couple of requests per second and with an overall code complexity51-of less than 4000 lines of code and something of larger scale. At some52-point it becomes important to integrate external systems, different53-storage backends and more.46+This is not unique to Flask. Many people use patched and modified47+versions of their framework to counter shortcomings. This idea is also48+reflected in the license of Flask. You don't have to contribute any49+changes back if you decide to modify the framework.50 55-If Flask was designed with all these contingencies in mind, it would be a56-much more complex framework and harder to get started with.51+The downside of forking is of course that Flask extensions will most52+likely break because the new framework has a different import name and53+because of that forking should be the last resort.54+55+Scaling like a Pro56+------------------57+58+For many web applications the complexity of the code is less an issue than59+the scaling for the number of users or data entries expected. Flask by60+itself is only limited in terms of scaling by your application code, the61+data store you want to use and the Python implementation and webserver you62+are running on.63+64+Scaling well means for example that if you double the amount of servers65+you get about twice the performance. Scaling bad means that if you add a66+new server the application won't perform any better or would not even67+support a second server.68+69+There is only one limiting factor regarding scaling in Flask which are70+the context local proxies. They depend on context which in Flask is71+defined as being either a thread or a greenlet. Separate processes are72+fine as well. If your server uses some kind of concurrency that is not73+based on threads or greenlets, Flask will no longer be able to support74+these global proxies. However the majority of servers are using either75+threads, greenlets or separate processes to achieve concurrency which are76+all methods well supported by the underlying Werkzeug library.modified:docs/foreword.rst+12 added-16 removed
15 unmodified lines16 17 For example, Flask uses thread-local objects internally so that you don't18 have to pass objects around from function to function within a request in19 order to stay threadsafe. While this is a really easy approach and saves20-you a lot of time, it also does not scale well to large applications.21-It's especially painful for more complex unittests, and when you suddenly22-have to deal with code being executed outside of the context of a request,23-such as in cron jobs.20+you a lot of time, it might also cause some troubles for very large21+applications because changes on these thread-local objects can happen22+anywhere in the same thread.23 25-Flask provides some tools to deal with the downsides of this approach, but26-the core problem remains. Flask is also based on convention over27-configuration, which means that many things are preconfigured and will28-work well for smaller applications but not so well for larger ones. For29-example, by convention, templates and static files are in subdirectories30-within the Python source tree of the application.24+Flask provides some tools to deal with the downsides of this approach but25+it might be an issue for larger applications. Flask is also based on26+convention over configuration, which means that many things are27+preconfigured and will work well for smaller applications but not so well28+for larger ones. For example, by convention, templates and static files29+are in subdirectories within the Python source tree of the application.30 32-But don't worry if your application suddenly grows larger33-and you're afraid Flask might not grow with it. Even with34-larger frameworks, you'll eventually discover that you need35-something the framework just cannot do for you without modification.36-If you are ever in that situation, check out the :ref:`becomingbig`37-chapter.31+However Flask is not much code and built in a very solid foundation and32+with that very easy to adapt for large applications. If you are33+interested in that, check out the :ref:`becomingbig` chapter.34 35 A Framework and an Example36 --------------------------37 50 unmodified lines