<<

1

Symfony vs Express: A Server-Side Framework Comparison

Magnus Greiff Andr´e Johansson

Faculty of Computing Blekinge Institute of Technology SE–371 79 Karlskrona, Sweden urn:nbn:se:bth-17945 2

This thesis is submitted to the Faculty of Computing at Blekinge Institute of Tech- nology in partial fulfillment of the requirements for the bachelor degree in Software Engineering. The thesis is equivalent to 10 weeks of full time studies.

Contact Information: Author(s): Magnus Greiff mangegreiff@gmail.com Andr`e Johansson [email protected]

University Advisor: Kenneth Lewenhagen Department of Computer Science and Engineering

Faculty of Computing Blekinge Institute of Technology SE–371 79 Karlskrona, Sweden Internet : www.bth.se Phone : +46 455 38 50 00 Fax : +46 455 38 50 57 3

Abstract

Context Considering the rising popularity of Node.js and the fact that a very large percentage of websites today are based on PHP, there is a need to understand the similarities and differences between these languages. Comparing their most popular server-side frameworks is valuable to developers in seeing the advantages of using one over the other - for both user and developer.

Objectives In this study we investigate how Express.js and Symfony compare against each other in terms of installation, functionality and performance. This will provide understanding of when to use JavaScript frameworks and when to use PHP frameworks for server-side projects.

Method A literature study was done to answer what similarities and differences exist between the frameworks. To explore how they compare in performance when mul- tiple users are actively sending requests to the server, an experiment was performed. Another experiment was carried out to measure performance in CPU-intensive ap- plications.

Results The result shows that both frameworks are quick to install and it is a fast process to setup a basic application. Both frameworks are highly cuztomizable and configurable because they are supported by a big open source community and the only difference is that Express is supportive of single-page applications which Sym- fony can not do on its own. Express was better than Symfony to handle multiple concurrent users when it comes to CPU usage and time it takes for the requests. For 100 and 1000 requests, Express CPU usage varied more than Symfony, but at 10000 and 100000 it varied less. In all tests with concurrent users, Express was faster. Tests performed in the second experiment showed that Symfony is only able to use 1 core when making the requests while Express is able to use multiple cores. Even though Symfony was limited by 1 core it was faster, most likely because it used more memory.

Conclusions This study shows that there are more similarities than differences between Express and Symfony. They both strive for high customization and high flexibility with a goal to make tedious tasks easier for the developer. Both rely on open source modules and components to add additional functionality. Out of the box, Express comes with less functionality as it strives to be minimalistic. However, to install Symfony is slightly quicker than Express and requires no code. There are currently more daily downloads of Express than Symfony, and therefore it’s considered more popular. It’s supportive of JavaScript-only for front- and back-end and is able to handle more concurrent users than Symfony, and is therefore better for high-traffic websites. But Symfony is able to handle CPU-intensive applications better than Express, and is able to load in large data sets faster, making it a good choice for applications with a lot of data and high CPU usage.

Keywords: Symfony, Express.js, PHP, JavaScript 4

Glossary

PHP - ”[...] is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.”[1]

JavaScript - According to Mozilla, ”JavaScript is a scripting or programming lan- guage that allows you to implement complex things on web pages”[2]

Asynchronous - Executing different parts of the code at the same time[3].

Synchronous - Executing code line by line, only executing the next line of code when the current has finished[3].

Scalability - ”Easiness to upgrade when your number of incoming request in- creases”[4].

Content Management System (CMS) - ”[...] is a software application or set of related programs that are used to create and manage digital content.”[5]

Single-Page Application (SPA) - An application where application code is only loaded on the initial request to the server[6].

Object Relational Mapping (ORM) - A way of writing SQL queries using object- oriented programming[7].

Model-View-Controller (MVC) - ”MVC is a framework for thinking about pro- gramming, and for organizing your program’s files.”[8]

Middleware - ”[...]functions executed in the middle after the incoming request then produces an output[...]”[9] Contents

1 Introduction 7 1.1Background...... 7 1.2Scope...... 8 1.3Purpose...... 9

2 Research questions 10 2.1Literaturestudy...... 10 2.1.1 Motivation...... 10 2.1.2 Expectation...... 11 2.2Experiments...... 11 2.2.1 Experiment1Motivation...... 11 2.2.2 Experiment1Expectation...... 12 2.2.3 Experiment2Motivation...... 13 2.2.4 Experiment2Expectation...... 13

3 Research Method 14 3.1Literaturestudy...... 14 3.1.1 Searchstrategy...... 14 3.1.2 Backward snowballing in iterations ...... 15 3.1.3 Limitations and criteria ...... 15 3.2Experiments...... 15 3.2.1 Preparation...... 15 3.2.2 Experiment1...... 18 3.2.3 Experiment2...... 19 3.2.4 Validity threats ...... 20

4 Literature review 21 4.0.1 Literature...... 21 4.0.2 Literaturecomparison...... 23

5 Result, Analysis & Discussion 24 5.1Result...... 24 5.2Analysis...... 32 5.2.1 Literature...... 32 5.2.2 Experiments...... 38 5.3Discussion...... 40

6 Conclusion 42

5 Contents 6

7 Future works 43

References 44

8 APPENDICES 48 8.1 Appendix A, Links ...... 48 8.1.1 Express Application ...... 48 8.1.2 Symfony Application ...... 48 8.1.3 Bombardier...... 48 8.1.4 SQLfileforresettingdatabase...... 48 8.1.5 ScriptforgeneratingSQLinsertfile...... 48 8.1.6 Expressroute...... 48 8.1.7 SymfonyController...... 48 8.2 Appendix B, Commands ...... 49 8.2.1 Bombardiercommand...... 49 8.2.2 Symfonywatchcommand...... 49 8.2.3 Symfonygrepcommand...... 49 8.2.4 Nodetopcommand...... 49 8.2.5 Nodegrepcommand...... 49 Chapter 1 Introduction

1.1 Background

It used to be that PHP and JavaScript worked together in order to create dynamic web pages[10]. JavaScript would handle the client-side tasks in the browser while PHP handled all the server-side tasks[10]. With the increasing popularity of JavaS- cript it has become more common to use it for server-side communication as well, through Node.js, which allows JavaScript code to be executed on server-side, remov- ing the need for any PHP at all[10]. However, both platforms continue to expand and improve, and while there are many who believe “JavaScript everywhere” is better, there are just as many who believe in the stability of PHP[10].

For a long time, PHP was the only option for back-end development, and 2018 stat- istics show that it is still the most commonly known and used language for server-side scripting[11]. In 2018, more than 80% of websites are built with PHP[11]. This is likely because the PHP syntax is simple, it can be easily integrated with HTML and has a large community that offers a lot of support[12]. That makes it the go-to language for beginner [12].

Similarly, JavaScript was for a long time only used for the front-end - handling the browser-side of things[13]. In 2009, Node.js was created[11] to allow developers to use a single programming language for both client- and server-side[13]. However, despite the rising interest in JavaScript as shown in Figure 1.1, only 0,4% of websites were built with Node.js in 2018[11]. The main advantage of Node.js is that it’s asynchronous, making it naturally faster than a synchronous application[3]. PHP, however, is synchronous by nature and therefore Node.js should have the advantage in speed and load times[3]. This makes Node.js ideal for scalable server-side, real-time and single-page applications, while PHP remains popular in CPU-heavy applications and Content Management Sys- tems (CMS) like Wordpress[15].

Often, frameworks are used in both languages as it makes applications easier to setup, faster to develop and more scalable[16]. For Node.js, the most popular frameworks are Express.js, Koa.js and Sails.js[16]. In PHP, it is , Symfony and CakePHP that are the most popular[16].

7 CHAPTER 1. INTRODUCTION 8

Figure 1.1: PHP (Blue) vs JavaScript (Red) web searches past 5 years [14]

1.2 Scope

The frameworks that we are going to focus on are Symfony (PHP) and Express.js (JS) because these are among the most used frameworks for the programming lan- guages PHP and JavaScript[17, 18, 19, 20]. In Figure 1.2 it shows a slight increase for Express and a slight decrease for Symfony over the last 5 years, despite Symfony being somewhat higher in popularity. This, we think, makes them the best choice for a comparison. We plan to investigate how they are different from each other and what similarities they might have. Mainly we will be looking at installation, functionality and popularity in both frameworks. We also plan to investigate which of them offers better performance when handling requests from multiple users, as well as when handling CPU-intensive requests with large amounts of data at once.

An attempt to run the CPU-intensive test in a browser showed that this gave an incorrect result as it was heavily based on how much data the browser could or couldn’t handle at once. It didn’t correctly show how the frameworks themselves affected the performance. Delivering 1 million rows of data in a browser took 4 hours where only 30-40 seconds were server load time, and the rest client load time. Therefore, we will only focus on delivering data to a client, and not include the rendering of it. CHAPTER 1. INTRODUCTION 9

Figure 1.2: Symfony (Blue) vs Express.js (Red) web searches past 5 years [21]

1.3 Purpose

The purpose of this paper is to give insight and better understanding for intermedi- ate developers. That is, those who have some knowledge with JavaScript and PHP, and can discuss those areas but may need guidance from time to time[22]. They may have little to no experience with JavaScript or PHP frameworks specifically, and our aim is to help them understand the similarities and differences between developing a server-side application with a JavaScript framework versus a PHP framework.

Considering that Node.js is rising in popularity while the absolute majority of ap- plications still use PHP (as mentioned in Chapter 1.1) the overall purpose of this thesis is to provide general understanding of when to use JavaScript and when to use PHP (if at all anymore) in newly-developed server-side applications. Chapter 2 Research questions

To perform this study we have devised the following research questions:

⇒ RQ1: What similarities and differences exists between the two frameworks?

⇒ RQ2: To what extent do multiple concurrent users affect the performance of each framework?

⇒ RQ3: How do the frameworks differ in terms of performance in very CPU- intensive applications with large amounts of data?

RQ1 will be answered through a literature study. RQ2 and RQ3 will be answered through two experiments.

2.1 Literature study

In the literature study, we will looking at the following to answer RQ1:

• Installation process - How difficult or simple the installation is.

• Functionality - What functionality they offer.

• Popularity - What makes them popular.

2.1.1 Motivation Before conducting experiments we want to know what qualities the frameworks pos- sess and if some of them overlap. Most importantly, we want to get an understanding of where Express excels and where Symfony excels. That being in which situations or which areas, and if they in somehow overlap as well or if they entirely different areas of expertise. This is done through learning about their functionality and why they are popular among other developers. We also want an idea of how the official documentations are in terms of accuracy and user friendliness, as that is a large part of choosing a framework.

10 CHAPTER 2. RESEARCH QUESTIONS 11

2.1.2 Expectation We expect to find that both frameworks are highly flexible and customizable. They will have similar installations with only a few commands to generate an empty pro- ject, and they will have tools available to easily add whatever components/modules the developer needs. Basic functionality like routing will be largely handled by the framework and therefore made easier for the developer. We expect the popularity of Express to be largely due to it allowing developers to use a single language for front- end and back-end. Popularity of Symfony probably rides a lot on the popularity of PHP or the fact that PHP is still largely used on the web.

2.2 Experiments

In RQ2, we will focus on the following:

• CPU usage - Peak of CPU usage on server during test

• Requests per second - Max and avg requests/s during test

• Total time - Total time to execute test

To see the success ratio of sent requests, we will also look at:

• Amount of invalid requests

• Amount of valid requests

With valid requests we mean that the request is received by the end user and a response code of 200 and with invalid requests we mean that the request did not get received by the end user and a response code that was not 200.

2.2.1 Experiment 1 Motivation Being server-side frameworks, we want to know which side best handles multiple users sending a lot of requests to the server at the same time. This should simulate a site having many different users using a reasonably-sized (in terms of file size) web site at the same time. CPU plays a big role in how much traffic a server can handle, and therefore we will focus mainly on that and how it is different for the frameworks. How many requests they can handle is also quite relevant to the performance as it shows which side is able to handle more traffic. And with this comes the ability to respond with a valid status code (2xx) and not have a high amount of non-valid responses from the server. Total time will also be measured to see which side is faster overall. CHAPTER 2. RESEARCH QUESTIONS 12

2.2.2 Experiment 1 Expectation We think that Express will perform better here in terms of lower CPU usage and ability to handle higher amount of requests per second. The responses to the re- quests will probably consist of more valid requests and very few invalid ones. This is because Express is asynchronous and therefore has better ability to handle many concurrent users. Symfony on the other hand will likely have much higher amount of invalid requests as it won’t be able to handle all the incoming requests as well. CHAPTER 2. RESEARCH QUESTIONS 13

For RQ3, we will look at performance as the following:

• CPU usage - Peak of CPU usage on server during test

• Memory usage - Peak of memory usage on server during test

• Load time - Total time to execute test

2.2.3 Experiment 2 Motivation After we have tested many concurrent users, we also want to test one user requesting large amounts of data at once which will simulate a very CPU-heavy application. Seeing how the frameworks respond to this shows their ability to handle, for example science websites or other types of websites that store and display a lot of data at once. Here we look at the CPU usage in every test to see exactly how much is used, if it varies and how different it is between frameworks. It is also likely that the large data-set will make the memory usage spike for a short time, so we will measure that to see if there is a difference despite the size of the data being the same. Additionally, load time will have some significance as it tells us which side is faster at loading in the data to the client. Some statements about PHP being better for CPU-intensive applications are being made on the web, but many that we have found aren’t backed up by references or their own experiments, like [23] and [24].

2.2.4 Experiment 2 Expectation The expectation here is that Symfony and Node both will use all of the CPU, but Symfony might be slightly quicker as PHP has been around for much longer than Node and is used a lot more on the web[11]. We think this contributes to PHP being better optimized. The general consensus is also that Node is mostly used for smaller applications for single individuals. PHP has had time to evolve more on the web, meaning it, and therefore Symfony, might be more accustomed to loading in large data-sets. Chapter 3 Research Method

3.1 Literature study

To perform this literature study we have read a wide variety of web articles, research papers and books, as well as official documentation for Express and Symfony.

3.1.1 Search strategy For searching web articles we primarily used Google’s search engine. When looking for research papers and books, we used Google Scholar, DiVA Portal and BTH Lib- rary search. Official documentation was found on official websites for Express and Symfony.

The following keywords were used in searches:

• JavaScript

• PHP

• Framework

• Comparison

• Express.js

• Symfony

• Performance

• Node.js

These keywords will be combined to create search strings to limit the amount of results.

14 CHAPTER 3. RESEARCH METHOD 15

3.1.2 Backward snowballing in iterations Backward snowballing was applied to a single starting paper, [25], because it was generally difficult to find relevant research papers relevant to our study. Snowballing was done by looking at the references of it and applying the criteria in section 3.1.3. This lead to two iterations, where in each iteration we looked at every reference to determine if it was relevant. In total we looked at all references of [25] and, in turn, all of their references. This lead to the first iteration giving us [26], and the second one [27] and [28].

3.1.3 Limitations and criteria Our criteria for selecting relevant articles and books are, for research papers, that they must be no older than 5 years and for web articles they must be no older than 2 years. This is because web articles generally are not backed by references and therefore become less reliable after a couple of years. The literature is considered relevant if it includes a comparison between frameworks, where at least one of the frameworks is Express or Symfony, or a single framework with presented function- ality and/or popularity. For web articles, we determine if a source is reliable by looking at the author’s profession, their other works and their experience in the field. With research papers, we skim through the abstract, look for mentions of PHP and JavaScript, and read the research questions to evaluate if it is relevant in our study.

3.2 Experiments

For the empirical study we will perform two experiments designed to answer RQ2 and RQ3.

3.2.1 Preparation Before performing experiments we have to prepare a server with a database filled with data, as well as two basic applications, as can be seen in Section 8.1, Appendix A, subsections 8.1.1 and 8.1.2. They are created with Express and Symfony respectively, accessible from outside the local network of the server.

3.2.1.1 Server We own a custom-built server, that we want to use for testing. Reason is, we don’t want to bombard a hosting provider with requests. This, however, means we’ll be using outdated hardware. But we’re only investigating difference in performance between applications, and not overall performance. Server specs are the following:

• OS: Debian Jessie 8.11

• CPU: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz

• RAM: 16GB 1333 MHz CHAPTER 3. RESEARCH METHOD 16

• Storage: 250GB HDD

We decide to keep the already running Apache version, but update the PHP version because some of the required Symfony components require later than the running PHP 5. To be consistent we also decide to keep the currently installed node version. The server will run:

• Apache version: 2.4.10

• PHP version: 7.3

• Node version: 9.2.0

Configuration is still necessary to allow for the kind of tests we want to do. In Apache configuration we have the following variables set (keep in mind these values are only used for testing purposes, a real production server should be carefully configured to match expected server load):

• Timeout 0 (Unlimited)

• KeepAlive On

• MaxKeepAliveRequests 0 (Unlimited)

• KeepAliveTimeout 0 (Unlimited)

Apache is by default configured to support 150 concurrent connections, and we de- cide not to change this because we did not want to do any changes to the default configuration and instead make sure we don’t go over 150 concurrent connections during testing. Next, we set the following in the .ini to allow PHP to use more memory:

• memory limit = 4096M

Lastly, Node needs to know it should run in production mode, and that it can use more memory. We set the following environment variables to configure Node:

• NODE ENV=production

• NODE OPTION=–max old space size=4096

3.2.1.2 Database We decide to use MySQL as it is the most commonly used database[29]. It is already installed and requires no special configuration, running version:

• MySQL version: 5.5.62 CHAPTER 3. RESEARCH METHOD 17

We have to keep this version in order to not cause problems for other applications normally running on the server.

However, we need data and tables to store it in. To do this, we created an .sql file, as shown in section 8.1, Appendix A, subsection 8.1.4, that automatically re-creates a database with a table of columns to hold some dummy data. In our case, the table will contain information about various clothing items. To fill the table with data, we created a script, as shown in section 8.1, Appendix A, subsection 8.1.5, that will create an .sql file with a long insert query. We input into the script, as an argument, how many rows of data we want, and it will create the appropriate query that we can then use to insert data into the database.

3.2.1.3 Applications For our test applications we want a simple web page that loads in data from the data- base and prints it to a page that we can view in a browser. However, in trying this we found that running tests in-browser was not viable due to the performance being mostly affected by the browser itself and not the server nor the frameworks. Instead we want to use the data from the database to create JSON objects that we return to the front-end, like an API. Then we can simply modify the size of the data to change the size of the response we get from a request, which will be application/json instead of text/html. This allows us to run terminal-based tests and get accurate results of how each framework performs on the server-side.

Then creating the test applications can be done in four steps. For each framework we need to:

1. Follow installation steps from our literature study

2. Connect the framework to the database

3. Get data from our database table

4. Return it as application/json to the front-end

To connect to the database and return data to the front-end, we simply used the offi- cial documentation for Express[30] and Symfony[31]. We only need some simple code to print the data, in the Express route shown in section 8.1, Appendix A, subsection 8.1.6 and the Symfony controller shown in section 8.1, Appendix A, subsection 8.1.7.

Production mode should be enabled for both applications to get the best performance out of them. Running Symfony in production means using Apache that’s pointing to Symfony’s public directory. For Node we have set the environment variable to run it in production mode.

3.2.1.4 Network Network plays a relatively important part in the test, and especially for the requests per second, response codes and total time. Therefore, we want run tests from a fast CHAPTER 3. RESEARCH METHOD 18 network (i.e. we want to send requests to the server from a fast network). We had access to a fast network so we decided that we want to run all tests from there. This also makes sure that we have a somewhat realistic scenario, by having the connec- tions be made from an outside network.

The network we had access to had a network speed of roughly 200 Mbit/s download and 200 Mbit/s upload. The server network has a speed of about 100 Mbit/s down- load and 100 Mbit/s upload. The largest amount of data we collect from a single request is 300 MB, so we think that these are considered good enough speeds to perform the tests and get accurate data.

The last thing we need to do is open up the port that the applications will be running on. To make sure the applications don’t interfere with each other in any way we only run one application at a time. These are hosted on port 3000 which is forwarded on the server network’s router. We find the public IP address for the server from https://www.whatismyip.com/, that we use to connect to the server when running tests.

3.2.2 Experiment 1 This experiment will be used to attempt to answer RQ2. To figure out how to test this, we did some research on tools that can be used to continuously send requests to a server through multiple connections simultaneously. After trying several, free and open source tools, we decided on one called ”bombardier”, that can be found in section 8.1, Appendix A, subsection 8.1.3. This because the tool had everything we need: Requests per second, response codes and total time. It also includes latency, throughput and uses fasthttp, a HTTP package tuned for fast performance.

Bombardier takes arguments to specify how many concurrent connections we want and how many requests we want the connections to send in total to the server, like shown in section 8.2, Appendix B, subsection 8.2.1. We decide to use 149 concurrent connections because 150 is the default max that Apache supports, and we want to reserve one connection for ourselves if we need it to measure performance.

We will do different number of requests in our tests, starting with 100, then 1000, 10000 and lastly 100000. This is to see if the frameworks behave differently based on how many requests are made - how they perform with a low amount of requests versus a very high amount of requests. The low amounts will simulate what we think is a somewhat realistic scenarios and the high amounts will be done to stress test the frameworks. Every request will get a page with 100 rows of data from the database, to simulate a moderately data-filled page. Each number will be tested 10 times to create a reasonably accurate average in our results.

The only thing we need to measure on the server is the CPU usage. The rest of the performance metrics, we get from our ”bombardier” tool. For Symfony, this has to be done through Apache’s server status module[32], because it is very difficult to measure in Debian, due to Apache creating separate processes for every open connec- CHAPTER 3. RESEARCH METHOD 19 tion. The server status is used by appending /server-status to the root URL to the server, which will direct to a page with performance metrics. But instead of having this open in a browser we want to use Linux’s ”watch” command combined with the ”wget” tool[33] to download the server status page every second and save it to a file, constructed like in section 8.2, Appendix B, subsection 8.2.2. Then the ”grep” command can be used to find the highest CPU value in the file, like in section 8.2, Appendix B, subsection 8.2.2, which will be the highest value CPU usage reached during the test.

When testing Node, we can simply use Linux’s ”top” command to see the CPU value, because Node runs on a single process. We choose ”top” because it’s clean and text-based, so we can easily use it remotely. This is done through a command that takes the row where the Node process is in the ”top” command, and saves it to a file every time it updates, as shown in section 8.2, Appendix B, subsection 8.2.4. The ”grep” command can then be used to find the highest CPU value in file , just like shown in section 8.2, Appendix, subsection 8.2.5.

In order to reset the server before each test, we follow this procedure: 1. Reboot server 2. Remove previous CPU data

3.2.3 Experiment 2 This experiment will attempt to answer RQ3. In order to perform this experiment, we want to do something in our applications that will make the CPU load spike. Having previously tried to load in 1 million rows from database and render it in a browser, we know that this is a very CPU-intensive scenario not only for the client but also for the server. Therefore we decide to use this test for our second experi- ment, minus the browser and rendering. We want to use the ”wget” tool to download a page with 1 million rows of data, through a terminal. This is because we get the same response from the server (as if we would request through a browser), but it lowers the client load time dramatically (from hours to seconds), thus enabling us to perform tests much quicker.

We will use the ”top” command like in section 8.2, Appendix B, subsection 8.2.4 to measure CPU usage as well as memory usage. This can be used for Symfony as well because we will only do one request from a single connection, meaning Apache will only use a single process for this connection. We only have to change ”node” in this command to ”apache”. The data from the ”top” command will be saved to a file every time it updates. After the test we get the highest CPU usage and highest memory usage during the test, through a ”grep” command like in section 8.2, Ap- pendix B, subsection 8.2.5. The ”wget” tool will give us the total time it took to get the page.

Each test will be done 5 times to get a reasonably accurate average. We don’t think a repeat of 10 times is necessary because we only measure 3 metrics and they don’t CHAPTER 3. RESEARCH METHOD 20

fluctuate much in between tests.

In order to reset the server before each test, we follow this procedure:

1. Reboot server

2. Remove previous CPU and memory data

3.2.4 Validity threats There are a few things that might threaten the validity of the study.

3.2.4.1 Response and load time measurements The valid response, invalid request and load time measurements might not be correct because they can be heavily affected by network layer and factors therein which have nothing to do with the frameworks.

3.2.4.2 Hardware The server hardware is outdated and while the components are good in theory, their age might be a factor in how well they perform. We don’t know exactly how much this can affect our results.

3.2.4.3 CPU and memory measurements via ”top” The ”top” command is sometimes slow to update the values it provides, which can therefore limit the measurements that can be done in a single quick-execution test, which in turn might not give the correct peak values and make the results vary too much.

3.2.4.4 Server contamination (Apache Node.js) The difference in the result could be an effect of the different server programs that we use instead of the framework itself. Chapter 4 Literature review

4.0.1 Literature Literature used for the study

Installing Express[34] Official ’getting started’ guide from Express. It clearly and simply shows which com- mands should be executed in order to create a base application with Express, along with some detailed comments.

Express ”Hello world” example[35] Straight-forward instructions for how to start the Express server to serve a web page. It includes all the code required to run the server and how to run it locally.

Pro Express.js: Master Express.js: The Node.js Framework For Your Web Development[36] A book about getting started with Express.js, how to use its functionality and some general tips.

Using Express.js to Create Node.js Web Apps[37] Step-by-step book guide for learning how to build scalable web applications with Express.js and Node.js. It takes it from what Express.js is to deploying a real-world application to production.

Web Development with Node and Express: Leveraging the JavaScript Stack[38] A book for intermediate JavaScript programmers, for learning how to build dynamic web applications with Express and Node. It goes through development of a fictional application with a public website and RESTful API.

Express In Action[39] For intermediate JavaScript programmers, this is a book about learning everything about Express. Including what is is, how to deploy applications into the real world and use RESTful API.

What Is Express.js? Why Is It So Popular JS Framework?[40] This web article goes through a list of reasons why Express is so popular, including

21 CHAPTER 4. LITERATURE REVIEW 22 many of its features. It also lists some of the basics of the framework.

Express, Koa, , Sails.js: Four Frameworks Of The Apocalypse[41] This article walks the reader through four of the most popular Node.js frameworks and in which areas each of them excel.

Installing & Setting up the Symfony Framework[42] Official Symfony documentation for installing and setting up the framework.

Symfony The Book[28] A comprehensive guide of the Symfony framework - what components it consists of and how they work.

Comparing Performance of Plain PHP and Four of Its Popular Frame- works[27] This paper evaluates performance of four of the most popular PHP frameworks as well as plain PHP and comparing the results.

Analysis and Practical Application of PHP Frameworks in Development of Web Information Systems[26] In this paper, the popularity of five popular PHP frameworks is discussed, as well as architecture and fundamentals of each framework. Also, through a performance test, it compares performance between frameworks.

Comparison between Symfony, ASP.NET MVC, And Node.js Express for Web Development[25] A comparison of three server-side frameworks, ASP.NET MVC 5, Symfony and Ex- press. In the paper they mainly look at development and performance for the com- parison. Security support and industry uses are also looked at.

Why Symfony Framework is so popular?[43] This article discusses the reasons behind the popularity of Symfony by going through how widely it is used on the internet and some of the benefits it brings to the table. It also provides some background information about the framework.

7 Good Reasons to Use Symfony Framework for Your Project[44] An article that walks through some of Symfony’s popularity and the biggest pros of using the framework, as well as some of the reasons why one should not use it. CHAPTER 4. LITERATURE REVIEW 23

4.0.2 Literature comparison References [34] - [41] are used for the literature study of Express.js. The first, [34] and second, [35] references are to the official Express documentation and are guides for getting started with Express.js. However, [34] only describes how Express is in- stalled, while [35] describes how to run the Express server.

Literature [36], [37], [38] and [39] are all quite comprehensive walkthroughs of the Express.js framework, including what it is, its functionality and how to use it. In [36] and [37] Mardan agreed that all the components that make Express.js represent the high customizability that Express is known for. However, [36] does not discuss libraries which according to [37] adds upon the ability to customize and allows for further flexibility. Both [36] and [37] list several tasks that are made much easier for developers by using Express, implying that the framework comes with functionality that helps with said tasks.

In [38] and [37] it’s said that Express seems to aim for flexibility but adds that min- imalism is also a big focus, considering that it has very little from the start and lets one choose what one needs afterwards.

References [40] and [41] discuss the popularity of Express. In [40] it goes on to say that the popularity is partly due to it being unopinionated and minimalistic, but both agree that it is largely thanks it allowing developers to use JavaScript for the back-end as well as front-end.

The focus of [42] - [44] is on Symfony and are used to make the Symfony part of the literature study. Here, only the first reference [42] is to the official documentation, which is for the install section of Symfony. The content of [28], [27], [26], [25] consist of heavier material and are used to study the functionality of the framework.

Both [28] and [27] say that Symfony is well-organized which promotes organized code as well as more reusable code. Both [26], [25] specifically mention the MVC design pattern as [28] also does when talking about organization and re-usability. They all conclude that Symfony strongly encourages this design pattern.

In [28], [27], [25] it is confirmed that the framework has built-in Object Relational Mapping, and [28], [26], [25] say that Symfony comes with Doctrine for database management.

To explain Symfony’s popularity, [43] and [44] come together and say that it is mainly due to the flexibility the framework offers in terms of components and bundles. Article [43] adds that Symfony being highly customizable makes it easy for developers to create custom features, which contributes to the popularity of the framework. Chapter 5 Result, Analysis & Discussion

5.1 Result

RQ1 What similarities and differences exists between the two frameworks?

The similarities between the two frameworks, as shown in Table 5.1, are that they both offer functionality that provides high customization, flexibility and that they both are quick to install. They require a single tool prior to installation, and once installed, both handle basic tasks like routing and offer open source modules to be added to an application to provide further functionality.

One of the main focuses of Express is also to be minimal and not offer too many components out of the box. This is not something Symfony has focus on. So Symfony offers a Database manager and ORM out of the box, but has no support for no-SQL which Express does. Express also requires one more command to install & serve an application, as well as 5 lines of code where Symfony requires none.

Comparison Symfony Express Require tool prior to installation Yes Yes Commands to install and serve app 2 3 Installation code None 5 lines Main focus Flexible Minimal & Flexible Main functionality Highly customizable Highly customizable Handle basics like routing Yes Yes Open source modules & components Yes Yes Database manager & ORM Yes No Support for No-SQL No Yes

Table 5.1: Symfony vs Express - what they offer out of the box

Express is mostly popular because of the ability to use JavaScript for back-end, and because it’s so minimalistic. Symfony’s popularity is due to its flexibility and high customizability. Express currently has 1.5 million daily downloads compared to Symfony’s 15,000.

24 CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 25

RQ2 To what extent do multiple concurrent users affect the performance of each framework?

When making 100 requests with multiple concurrent users the impact on the server’s CPU usage was low and all tests complete with 100% valid requests, as shown in Figure 5.1. However, Express was able to execute the requests 5.2 seconds faster than Symfony as shown in Table 5.2.

Figure 5.1: CPU Usage (%) comparison between Express and Symfony. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 26

Framework Valid Requests Invalid Requests Time(s) 100 0 6 Symfony 100 0 5 100 0 5 100 0 6 100 0 6 100 0 6 100 0 6 100 0 6 100 0 5 100 0 6 Average 100 0 5.7 100 0 1 Express 100 0 1 100 0 1 100 0 1 100 0 1 100 0 0 100 0 0 100 0 0 100 0 0 100 0 0 Average 100 0 0.5

Table 5.2: Valid/Invalid Requests and Time for 100 requests.

As seen in Figure 5.2, the CPU usage of Express started to vary a lot in between tests. Symfony’s CPU usage doesn’t vary as much. Symfony was 2.9 second slower and all tests completed with 100% valid requests as seen in Table 5.2. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 27

Figure 5.2: CPU Usage (%) comparison between Express and Symfony.

Framework Valid Requests Invalid Requests Time(s) 1000 0 9 Symfony 1000 0 9 1000 0 8 1000 0 8 1000 0 8 1000 0 7 1000 0 9 1000 0 11 1000 0 9 1000 0 9 Average 1000 0 8.7 1000 0 6 Express 1000 0 6 1000 0 5 1000 0 6 1000 0 7 1000 0 6 1000 0 5 1000 0 6 1000 0 6 1000 0 6 Average 1000 0 5.9

Table 5.3: Valid/Invalid Requests and Time for 1000 requests. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 28

When making 10000 requests, Symfony’s CPU usage varied a slightly more while Express started to vary a lot less, as shown in Figure 5.3. Additionally, Table 5.4 shows that the Symfony tests resulted in an average of 128 invalid requests while Express only had 1 in 6 of the accepted tests. The other 4 tests did not meet the method requirements and showed deviating results. Express was also 4.3 seconds quicker on average to execute tests.

Figure 5.3: CPU Usage (%) comparison between Express and Symfony. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 29

Framework Valid Requests Invalid Requests Time(s) 9737 263 80 Symfony 9963 37 42 9542 458 80 9970 30 63 9960 40 51 9967 33 43 9753 247 79 9883 117 51 9967 33 43 9979 21 41 Average 9872.1 127.9 57.3 10000 0 50 Express 10000 0 53 10000 0 56 10000 0 50 9999 1 55 10000 0 54 Average 9999.8 0.2 53

Table 5.4: Valid/Invalid Requests and Time for 10000 requests.

When making 100000 requests, Express CPU usage varied very little while variations in Symfony’s CPU usage increased, as Figure 5.4 shows. Average amount of invalid requests, as seen in Table 5.5 for Symfony went up to 2774 and Express only showed an average of 186. The time difference increased to 224 seconds on average, where Express was the fastest. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 30

Figure 5.4: CPU Usage (%) comparison between Express and Symfony.

Framework Valid Requests Invalid Requests Time(s) 96162 3838 712 Symfony 98935 1065 678 96930 3070 725 93735 6265 713 98817 1183 543 97849 2151 683 97208 2792 657 97320 2680 810 97359 2641 739 97944 2056 603 Average 97225.9 2774.1 686.3 99998 2 412 Express 100000 0 357 99999 1 360 100000 0 483 99738 262 583 99259 741 505 99455 545 471 99688 312 503 100000 0 460 100000 0 490 Average 99813.7 186.3 462.4

Table 5.5: Valid/Invalid Requests and Time for 100000 requests. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 31

RQ3 How do the frameworks differ in terms of performance in very CPU-intensive applications with large amounts of data?

During CPU-intensive applications, Symfony utilizes more memory than Express and is able to perform the test quicker as shown in Table 5.6. Symfony is maxed at 100% CPU usage while Express is able to go beyond to an average of 126%.

Framework CPU Usage(%) Memory Usage(%) Time(s) 100 18 36 Symfony 100 15.8 40 100 21.1 38 100 20.5 37 100 19.7 35 Average 100 19.02 37.2 117.7 8.3 43 Express 125.7 12.1 45 129.7 11.4 49 131.7 10.3 43 127.3 12.2 45 Average 126.42 10.86 45

Table 5.6: CPU, MEM and Time for retrieving 1million rows of data with wget. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 32

5.2 Analysis

This section includes analyses of the results.

5.2.1 Literature This is the analysis of the literature study.

Express Analysis of the installation, functionality and popularity of the Express.js framework.

Installation process Installing and creating a basic express application is a quick process if one has Node installed[34]. The first action is to figure out where one wants the express application to be located on the machine[34]. Once decided, the location has to be initiated with npm with the command ‘npm init‘ which will create a file called package.json[34]. Inside package.json it will save all the dependencies that the application will use[34]. After the package.json has been created, the installation of Express itself can begin by running the command ‘npm install express –save‘[34].

After having installed Express following files and directory will be visible in the location:

Figure 5.5: Files after NPM init and express installation.

When all files are there the installation can be continued by creating a file called index.js with JavaScript code required to be able to launch the express server[35]. The code required to launch the Express server is as followed (see Figure 5.6)[35]: With those lines of code in the index.js file, Express is ready to serve a web page on the machine on port 3000. The application can be launched by using the command ‘node index.js‘[35]. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 33

Figure 5.6: Basic Express application

Functionality Express.js is based on the Node.js and works through components which act as middleware[36]. They represent the most important thing that Express.js has to offer - high customization[37][36]. Developers are also able to freely pick which libraries they need for their project - which allows for more flexibility as well as quicker development and easier maintenance[37]. For example, it helps with mundane tasks such as the following:

• Managing requests • Managing cookies • Session management • Error handling • Organization of routes • Getting URL parameters • Setting response headers

[37][36]

The main aim of Express.js is to be a minimal and flexible framework[38]. Instead of giving everything to the developer right from the start, it provides the freedom of choosing what to add it to the framework[38]. This is to prevent overwhelming the developer with a big, complex project before they’ve even started, and having to remove functionality they don’t need[38].

Express.js is also very supportive of single-page applications, where basically the en- tire site is downloaded on the initial network request[37]. Afterwards, the application requires minimal communication with server to supply all routes in the application, leading to much faster navigation[37]. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 34

The great benefit of using Express.js (and Node.js) over other frameworks is that the front- and back-end can both be written in JavaScript, and therefore developers don’t need to learn a whole new language for the back-end[39]. In terms of database, the most popular to use is MongoDB, which is a no-SQL JavaScript-friendly data- base[39]. But it also supports SQL relational databases or any other kind of storage mechanism[39].

Popularity What makes Express.js so popular when developing websites? According to From- dev[40] it is because ”Express.js is quick, not opinionated, and minimalist web frame- work for node.”. Express allows developers to use JavaScript to develop their back- end functionality for their website[40].

With the demand growing for web applications, JavaScript has become one of the most popular programming languages when creating web application[41]. And with Node.js it is now possible to write back-end functionality using JavaScript[41]. With the help of Express.js, a Node.js application can now get access to ”web application features”[41], that will help with navigation and render static files like images, style sheets and JavaScript. Because Express.js is of the minimal size when it comes to frameworks, it does not compromise the performance given by Node.js[40].

Figure 5.7 shows the day by day growth that Express.js has done over the past 5 years. It shows that it has grown from a few thousand downloads in late 2014, early 2015, to around 100-150 thousand in middle of 2015. As of today Express.js has around 1,5 million downloads per day and it is still going up.

Figure 5.7: Amount of downloads per day over 5 year span[45]. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 35

Symfony Analysis of the installation, functionality and popularity of the Symfony framework.

Installation process Installing and creating an basic Symfony application is a quick process with the right tool already installed. A tool called is needed to help with the installation process[42]. With it installed, all that is required is to download the Symfony website skeleton with the help of the command shown in Figure 5.8[42]:

Figure 5.8: Command for installing and downloading basic Symfony application.

With the website skeleton downloaded, the server can be started. This is done through the command show in in Figure 5.9[42]

Figure 5.9: Command for starting the Symfony application.

The application can then be accessed through a browser using the address: 127.0.0.1:8000[42]. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 36

Functionality Symfony includes a powerful set of independent tools in a bundle that allows for endless configuration[28]. Among these are high-quality open source tools developed by the community[28]. But by default, Symfony comes with twenty libraries, called the Symfony Components[28]. Among these are the following:

• HttpFoundation - Classes for handling requests, sessions, file uploads and more.

• Routing - Routing system for fast and configurable routing

• Form - Classes for easy form creating and handling

• Validator - System for configuring rules that are used to validate user-submitted data

• Templating - Toolkit for rendering templates (i.e. a layout template)

• Security - Library for handling all types of security in an application

• Translation - Library for translating strings

The goal is to let developers focus on building their applications, without worrying about the tools and background systems they require, such as routing[28]. It also helps keep the code organized and reusable[28]. In fact, files are organized in sections in the file structure[27].

Furthermore, the framework encourages the use of the MVC design pattern[28][27][26], and has built-in Object Relational Mapping[28][27][25]. For database management, Symfony comes equipped with Doctrine[26][25][28], and supports multiple databases such as MySQL, PostgreSQL, SQLite, etc[25]. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 37

Popularity What makes Symfony so popular among developers? According to Business Mat- ters[43] and Hackernoon[44] it is because of its flexibility when it comes to features like components and bundles. Symfony is used by many big platforms, i.e , phpBB and more[44]. Symfony is highly customizable and it makes it easier for de- velopers to develop custom features[43].

Figure 5.11 shows the amount of downloads of the Symfony framework without any other components over a 5 year span. Symfony actually contains many other components[46] and if one includes all the components (packages), the total amount of downloads is almost 2,4 billion total downloads[47].

Figure 5.10: Symfony total downloads of all components[47].

Figure 5.11: Amount of downloads per day over 5 year span[48] CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 38

5.2.2 Experiments This is the analysis of the performed experiments.

5.2.2.1 RQ2 In the following section we will analyze the result from our experiment to answer RQ2.

CPU Usage for 100 Requests As shown in Figure 5.1 the difference in CPU Usage is quite large. Symfony had a peak of 4.77% while Express had a peak of 15%, which is a 10.23% difference. Sym- fony had a low of 1.21% while Express had a low of 10%, which is a 8.79% difference.

Valid/Invalid Requests and Time for 100 Requests Both Express and Symfony could handle 100 requests with ease which is shown in chart Table 5.2. All requests came through. The only big difference between Express and Symfony for this test is the time it took to execute the tests. Symfony had an average time of 5.7 seconds while Express had an average time of 0.5 seconds, making Express 5.2 seconds faster.

CPU Usage for 1000 Requests With the increase of the total amount of requests, the difference between CPU Us- age for Symfony and Express has increased a lot as shown in Figure 5.2. Symfony only had a peak of 14.25% while Express had a peak of 69.5%, which is a 55.25% difference. Symfony had a low of 10.58% while Express had a low of 27.9%, which is a 17.32% difference.

Valid/Invalid Requests and Time for 1000 Requests While making 1000 requests both Express and Symfony could deliver all requests as shown in Table 5.3. If comparing the time it took for 100 requests and 1000 requests, Symfony only had an increase of 3 seconds while Express had an increase of 5.4 seconds, but Symfony is still 2.9 seconds slower than Express.

CPU Usage for 10000 Requests When increasing the amount of requests, it seems that the CPU usage for Express is starting to vary less. As shown in Figure 5.3, Express CPU usage is now variating much less than it was when doing 1000 requests. Express highest peak is now 73.8%, while Symfony’s highest peak was 56.95%, which is a 16.85% difference. Express had its lowest peak at 71.5% while Symfony had a low of 46.69%, which is a 24.81% difference. The difference between Express highest peak and lowest peak is now only 2.3%, while with 1000 requests the difference was 41.6%. The difference between Symfony’s highest and lowest peak is now 10.26%, while the difference for 1000 re- quest was 3.67%.

Valid/Invalid Requests and Time for 10000 Requests With the increase to 10000 request, the amount of invalid requests are increasing for Symfony. As shown in Table 5.3 it went from 0 invalid requests for both Express and CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 39

Symfony on average, to 0.2 invalid requests on average for Express and 127.9 invalid requests on average for Symfony as shown in Table 5.4. The invalid requests may be due to a network interruption and more investigation would be need to answer why they happen.

According to Table 5.4, Symfony was faster to complete all the requests with an average of 57.3 seconds, while Express had an average of 53 seconds. Only 6 tests were accepted for Express because the other 4 did not correctly follow the method requirements and showed deviating results. These specific tests were not performed from the agreed-upon network - due to illness these had to be done from a home network which might have influenced the results. Thus, they were removed.

CPU Usage for 100000 Requests The CPU usage for Express is variating less with measures around 74-75% but there is an exception and that is the the first test where the CPU usage spiked to 88.1%. When it comes to Symfony Figure 5.4 shows that that the CPU usage started variat- ing more when more requests are done. Express had its highest peak at 88.1%, while Symfony had its highest peak at 99.23%, which is a 11.13% difference. Express had its lowest peak at 74.1%, while Symfony had its lowest peak at 60.25%, which is a 13.85% difference.

If comparing the result from the 10000 request test and this one, the CPU usage for Express has only risen from around 71-73% to 74-75%, which is not much when the amount of requests has increased by 10 times. But on the other-hand, Symfony has risen from around 46-56% to 60-99%, which was an expected result when in- creasing the amount of requests by 10.

Valid/Invalid Requests and Time for 100000 Requests The amount of invalid requests continues to increase when increasing the total amount of requests. As shown in Table 5.5, the average amount of invalid requests for Symfony is 2774.1 requests, while Express only has an average of 186.3 invalid requests.

Symfony had an average test time of 686.3 seconds which is slower than Express average test time of 462.4 seconds. Once again Express is faster than Symfony, this time the difference is 223.9 seconds, which is a substantial amount of time, consid- ering that Symfony is using more CPU.

Overall On average, Express is able to handle 56 more requests per second than Symfony, with 149 concurrent users. And Symfony has an average of 1358 more invalid re- quests. This, combined with Express being 52.95 seconds faster overall, shows that the impact on Symfony is much bigger. Express is also showing less variation in CPU usage at 100000 requests being sent from 149 connections - averaging 76.62% while Symfony is at 87.25%. This proves Express’ ability to handle high amounts of traffic. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 40

5.2.2.2 RQ3 As shown in Table 5.6, Symfony was the fastest framework to fetch 1 million rows using wget, being 7.6 seconds faster on average. Symfony was faster than Express even though Symfony is limited to 1 core and 100% CPU usage, while Express can run on multiple cores, as shown through its ability to use more than 100% CPU. Symfony is averaging 100% CPU while Express averaging 126.42% CPU usage. The memory usage was higher for Symfony than Express, with Symfony averaging 19.02% and Express averaging 10.86%, which could be the cause of Symfony being a little bit faster. This also presents a weakness in Express’ ability to handle CPU-heavy tasks and large data sets.

5.3 Discussion

In this section we will have a discussion about the analysis.

RQ1 What similarities and differences exists between the two frameworks?

Our literature study shows that the installation process and the effort required to create an empty project is very minimal for both frameworks, as we initially ex- pected. Express requires two commands to install and then the manual creation of index.js with the required code to launch the application. Symfony, on the other hand, requires only one command before the server can be started. While the pro- cess is minimal for both applications, Symfony has the slight advantage.

Express and Symfony both strive for high customization and configuration, through open source, community-developed tools and libraries. This is meant to add flexib- ility for developers to add features that they want, without developing them from scratch and without adding things they don’t need. Both frameworks do this very well, and they especially have a focus on delivering functionality that makes mundane tasks much easier for the developer. This is almost exactly what we expected.

Arguably, the biggest difference is that Express is very supportive of single-page applications, which Symfony can’t do on its own. Using Express also allows for JavaScript-only development, largely contributing to its popularity as we thought, whereas with Symfony, one need knowledge of PHP and most likely JavaScript as well. So while the frameworks have a lot of similarities, the differences in our analysis weigh in favor of Express.

RQ2 To what extent do multiple concurrent users affect the performance of each framework?

When making 100 requests, there is a little CPU usage for Symfony and more for Express. However, Express goes through the requests significantly faster than Sym- fony, implying that Express better utilizes the CPU to deliver faster performance in this case. There are no bad responses for either side. CHAPTER 5. RESULT, ANALYSIS & DISCUSSION 41

Increasing the request amount to 1000 shows that Symfony’s CPU usage is affected very little, it lays around 10-14% during all the tests, while Express starts to fluc- tuate and goes from around 27% to around 69%. There are still no invalid requests at this point, but the time to execute the test for Express has gone up moderately, while still remaining below Symfony’s average time.

With 10000 requests Express is starting to stabilize in terms of CPU usage, while Symfony is variating more in CPU usage. It also shows some invalid requests from both sides, with Symfony having 127.7 more than Express.

Lastly, with 100000 requests, Express shows that it has stabilized quite well, but Symfony is still variating more in CPU usage. Symfony has also passed Express and is using more CPU, despite taking much longer to complete the requests.

This confirms our expectations that Express is better at handling more requests per second and requests in general. However, it is mostly using more CPU than Symfony, which is not what we thought.

RQ3 How do the frameworks differ in terms of performance in very CPU-intensive applications with large amounts of data?

During this test it shows that Symfony is able to only use one core, while Express can use multiple cores. This will result in that Express will get higher CPU usage during the test and Symfony will be limited to 100% CPU usage. Even though Sym- fony was limited to 100% CPU usage, Symfony was faster on average to complete the tests, with Symfony completing the tests on average 37.2 seconds and Express taking on average 45 seconds to complete the tests. We believe that this is because Symfony uses more memory during the test than Express does. Symfony used on average 19.02% memory while Expressed used 10.86%. Showing that Symfony per- forms better in CPU-heavy applications, but only when utilizing more memory. This presents a weakness in Express’ ability to handle CPU-heavy tasks and large data sets. However, this particular problem could be circumvented by avoiding loading in large amounts of data at once.

We were wrong in thinking that both frameworks would use all of the CPU, because we didn’t account for Node being able to use multiple cores, and Symfony only using a single core. However, our expectations that Symfony would be able to handle it better were right. Chapter 6 Conclusion

Express and Symfony are very similar when comparing the server-side on its own. They strive for high customization and high flexibility with a goal to make tedious tasks easier for the developer. Both rely on open source modules and components to add additional functionality. Out of the box, Express comes with less functionality as it strives to be minimalistic. However, to install Symfony is slightly quicker than Express and requires no code.

In Express, JavaScript, a language previously only for client-side programming, can also be used for back-end. For many, this alone can be a deciding factor when choos- ing a framework or a programming language and it is concluded to be the main reason for Express’ popularity. Express currently has 1.5 million daily downloads while Symfony only has 15,000.

In terms of performance, multiple concurrent user appear to have big impact on Symfony. This is shown by Symfony having a lot of invalid requests and takes much longer than Express to complete the requests. At higher levels of requests Express shows less variation in CPU usage than Symfony does, thus concluding that Express is better equipped to handle high amounts of traffic.

CPU-intensive applications, however, show where Express is weaker. When loading a million rows from a MySQL database, Symfony is faster on average despite only being able to use a single CPU core where on the other hand Express is able to use multiple cores. Symfony is utilizing more memory than Express, thus concluding that memory plays a big part in this kind of requests and leads to better performance.

Overall, it seems that Symfony is good at CPU-heavy tasks such as loading in large amounts of data at once. But Express is superior in terms of handling large amounts of traffic. And since dividing data into smaller functions and using techniques like lazy loading (meaning not loading data until it is needed) are valid ways to handle this kind of request, Express is a clear choice for high-traffic websites. But Symfony is a good choice for low-traffic sites with a lot of data.

42 Chapter 7 Future works

To continue work, it would be possible to further investigate RQ2 and RQ3 by adding more tests, increasing amount of iterations of each test, running tests from different networks and using up-to-date hardware for the server. In doing this, it’s also possible to do an investigation as to why some requests start failing at a higher amount of requests. Additionally, one could investigate where exactly more invalid requests start happening. More frameworks could also be added to the study for a more accurate and in-depth answer to all the research questions. If one wants to see how different databases affect the frameworks they could repeat the study using different databases. For further accuracy, it would be possible to run tests on several different applications and applications that are more representative of those in real life.

43 References

[1] N/A. What is PHP? url: https://secure.php.net/manual/en/intro- whatis.php (visited on 05/03/2019). [2] A Vishal. What is JavaScript? 5th Feb. 2019. url: https : / / developer . mozilla.org/en- US/docs/Learn/JavaScript/First_steps/What_is_ JavaScript (visited on 05/03/2019). [3] P Hooda. PHP vs. Node.js. 29th Apr. 2018. url: https://www.geeksforgeeks. org/php-vs-node-js/ (visited on 05/03/2019). [4] S. Arya. What the hell is scalable code anyway? 7th Apr. 2017. url: https: //blog.sarasarya.com/what- the- hell- is- scalable- code- anyway- f6626ad78227 (visited on 18/03/2019). [5] M. Rouse. content management system (CMS). 3rd June 2016. url: https:// searchcontentmanagement.techtarget.com/definition/content-management- system-CMS (visited on 18/03/2019). [6] F. Copes. What is a Single Page Application? 11th Nov. 2018. url: https: //flaviocopes.com/single-page-application/ (visited on 14/05/2019). [7] M. Hoyos. What is an ORM and Why You Should Use it. 24th Dec. 2018. url: https://blog.bitsrc.io/what-is-an-orm-and-why-you-should-use- it-b2b6f75f5e2a (visited on 14/05/2019). [8] N/A. MVC: Model, View, Controller. url: https://www.codecademy.com/ articles/mvc (visited on 14/05/2019). [9] A. Abel. A Simple Explanation Of Express Middleware. 6th Dec. 2017. url: https : / / medium . com / @agoiabeladeyemi / a - simple - explanation - of - express-middleware-c68ea839f498 (visited on 14/05/2019). [10] P Wayner. PHP vs. Node.js: An epic battle for developer mind share.9thFeb. 2017. url: https://www.infoworld.com/article/3166109/application- development/php- vs- nodejs- an- epic- battle- for- developer- mind- share.html (visited on 04/02/2019). [11] S Mavani. Node.js vs PHP. 24th Sept. 2018. url: https://dev.to/sandipmavani/ nodejs-vs-php-52g4 (visited on 05/03/2019). [12] N/A. PHP vs. Node.js: Which Is the Best for Server-Side Development? 24th Sept. 2018. url: https://www.sam-solutions.com/blog/node- js- vs- php- which-is-the-best-for-server-side-development/ (visited on 05/03/2019). [13] E Plesky. PHP Vs Node.Js: Which Is Better? 5th Apr. 2018. url: https: //www.plesk.com/blog/product-technology/php-vs-node-js/ (visited on 05/03/2019).

44 REFERENCES 45

[14] url: https://trends.google.com/trends/explore?date=today%205- y&q=%2Fm%2F060kv,%2Fm%2F02p97 (visited on 30/05/2019). [15] P Vuollet. Comparison: Node.js vs. PHP. 4th Jan. 2019. url: https:// stackify.com/node-js-vs-php/ (visited on 11/03/2019). [16] N/A. Node JS vs PHP for Server-Side Development. 8th Feb. 2018. url: https://applikeysolutions.com/blog/node-js-vs-php-for-server- side-development (visited on 11/03/2019). [17] A Njenga. 10 Popular PHP frameworks in 2019”, RayGun, November 2018. 21st Nov. 2018. url: https://raygun.com/blog/top- php- frameworks/ (visited on 25/02/2019). [18] A Molde. op 10 PHP Frameworks for Web Development. 8th Aug. 2018. url: https://stackify.com/php-frameworks-development/ (visited on 25/02/2019). [19] A Goel. Top 10 Web Development Frameworks in 2019. 8th Feb. 2019. url: https://hackr.io/blog/top-10-web-development-frameworks-in-2019 (visited on 25/02/2019). [20] R Benitte, S Greif, M Rambeau. Back-end Frameworks - Overview. url: https: / / 2018 . stateofjs . com / back - end - frameworks / overview/ (visited on 25/02/2019). [21] url: https://trends.google.com/trends/explore?date=today%205- y&q=%2Fm%2F09cjcl,%2Fm%2F0_v2szx (visited on 30/05/2019). [22] N/A. Competencies Proficiency Scale. 12th Jan. 2009. url: https : / / hr . nih.gov/working-nih/competencies/competencies-proficiency-scale (visited on 25/02/2019). [23] N. Chrzanowska. Node.js vs. PHP: Which Environment To Choose For Your Next Project? 7th Sept. 2017. url: https://www.netguru.com/blog/nodejs- vs-php (visited on 13/05/2019). [24] K. Padia. Is Node.js really better than PHP? Let’s go Through the Pros and Cons. 2nd Aug. 2019. url: https : / / datafloq . com / read / is - nodejs - better-than-php-pros-cons/5297 (visited on 13/05/2019). [25] J. Mao. COMPARISON BETWEEN SYMFONY, ASP.NET MVC, AND NODE.JS EXPRESS FOR WEB DEVELOPMENT. url: https://library.ndsu.edu/ ir/bitstream/handle/10365/28191/Comparison%20between%20Symfony, %20ASP.NET%20MVC,%20And%20Node.js%20Express%20for%20Web%20Development. pdf?sequence=1 (visited on 24/03/2019). [26] V Boltunovaa N Prokofyevaa. Analysis and Practical Application of PHP Frame- works in Development of Web Information Systems. url: https : / / www . sciencedirect . com / science / article / pii / S1877050917300601 (visited on 24/03/2019). [27] J. Samra. Comparing Performance of Plain PHP and Four of Its Popular Frameworks. url: https : / / www . diva - portal . org / smash / get / diva2 : 846121/FULLTEXT01.pdf (visited on 24/03/2019). REFERENCES 46

[28] N/A. Symfony The Book. url: https://symfony.com/pdf/Symfony_book_ 3.1.pdf (visited on 24/03/2019). [29] S. Babeni. Most Popular Databases in 2019: Here’s How They Stack Up. 24th Jan. 2019. url: https://ormuco.com/blog/most-popular-databases (visited on 13/05/2019). [30] N/A. Database integration. url: https://expressjs.com/en/guide/database- integration.html#mysql (visited on 13/05/2019). [31] N/A. Databases and the Doctrine ORM. url: https://symfony.com/doc/ current/doctrine.html (visited on 13/05/2019).

[32] N/A. Apache Module modstatus. [33] N/A. Introduction to GNU Wget. [34] N/A. Installing. url: https://expressjs.com/en/starter/installing. html (visited on 11/03/2019). [35] N/A. Hello world example. url: https : / / expressjs . com / en / starter / hello-world.html (visited on 11/03/2019). [36] A. Mardan. Pro Express.js: Master Express.js: The Node.js Framework For Your Web Development. url: https://books.google.se/books?hl=en& lr=&id=o1EnCgAAQBAJ&oi=fnd&pg=PP3&dq=express.js&ots=mnijjq3jBZ& sig=6SvhMI2fWGGvN6Gf21rwE2cILOU&redir_esc=y#v=onepage&q&f=false (visited on 25/03/2019). [37] A. Mardan. Using Express.js to Create Node.js Web Apps. 3rd Nov. 2018. url: https://link-springer-com.miman.bib.bth.se/chapter/10.1007/978- 1-4842-3039-8_2 (visited on 25/03/2019). [38] E. Brown. Web Development with Node and Express: Leveraging the JavaScript Stack. 17th July 2015. url: https://books.google.se/books?hl=en&lr= &id=1cHvAwAAQBAJ&oi=fnd&pg=PP1&dq=express.js&ots=BrxVpkQuj3&sig= VWM37zSM3Q7dpllvcerj72hgsn4&redir_esc=y#v=onepage&q=express.js& f=false (visited on 25/03/2019). [39] E. Hahn. Express in Action. 2016. url: https://www.hackerstribe.com/wp- content/uploads/2016/04/Node.js-Express-in-Action.pdf (visited on 25/03/2019). [40] S Smith. What Is Express.js? Why Is It So Popular JS Framework? 23rd Oct. 2017. url: https://www.fromdev.com/2017/10/what-is-expressjs-why- is-it-so-popular.html (visited on 18/03/2019). [41] C Yang. Express, Koa, Meteor, Sails.js: Four Frameworks Of The Apocalypse. url: https://www.toptal.com/nodejs/nodejs-frameworks-comparison (visited on 18/03/2019). [42] N/A. Installing Setting up the Symfony Framework. url: https://symfony. com/doc/current/setup.html (visited on 11/03/2019). [43] B Matters. Why Symfony Framework is so popular? 20th Dec. 2018. url: https://www.bmmagazine.co.uk/business/why-symfony-framework-is- so-popular/ (visited on 26/03/2019). REFERENCES 47

[44] S Hansen. 7 Good Reasons to Use Symfony Framework for Your Project. 29th Nov. 2017. url: https://hackernoon.com/7-good-reasons-to-use-symfony- framework-for-your-project-265f96dcf759 (visited on 26/03/2019). [45] P. Vorbach. Download statistics for package express. url: https://npm-stat. com/charts.html?package=express&from=2014-03-17&to=2019-03-17 (visited on 18/03/2019). [46] N/A. Symfony Components. url: https://symfony.com/components (visited on 18/03/2019). [47] N/A. Symfony Downloads Stats. url: https://symfony.com/stats/downloads (visited on 18/03/2019). [48] N/A. symfony/symfony install statistics. url: https : / / packagist . org / packages/symfony/symfony/stats (visited on 19/03/2019). Chapter 8 APPENDICES

8.1 Appendix A, Links

8.1.1 Express Application https://github.com/MagnusGreiff/exjobb_express

8.1.2 Symfony Application https://github.com/andymartinj/symfony-perf

8.1.3 Bombardier https://github.com/codesenberg/bombardier

8.1.4 SQL file for resetting database https://github.com/MagnusGreiff/exjobb_express/blob/master/sql/table.sql

8.1.5 Script for generating SQL insert file https://github.com/MagnusGreiff/exjobb_express/blob/master/sql/dummy.sh

8.1.6 Express route https://github.com/MagnusGreiff/exjobb_express/blob/master/routes/async. js

8.1.7 Symfony Controller https://github.com/andymartinj/symfony-perf/blob/master/src/Controller/ Home.php

48 CHAPTER 8. APPENDICES 49

8.2 Appendix B, Commands

8.2.1 Bombardier command In this command we run tests with 100, 1000, 10000 and 100000 after the -n argu- ment.

bombardier −c149−n

8.2.2 Symfony watch command For measuring Symfony’s CPU usage and appending it to file

watch −n1”wget−O − http://IP:PORT/server−status?auto −>> symfony. txt”

8.2.3 Symfony grep command Find highest Symfony CPU value in file and print it

grep −o −P’(?<=CPULoad : ) . ∗(?=) ’ ./symfony. txt | sort −rn | head −n1

8.2.4 Node top command Used for measuring CPU usage by Node

top | grep −− line−buffered node >> node . txt

8.2.5 Node grep command Find highest Node CPU value in file and print it

grep −o −P’(?<=[A−Z]).∗ (?= [0−9].[0−9])’ ./node. txt | sort −rn | head −n1