Thursday, February 18, 2016

Test Automation in Selenium Using Page Object Model and Page Factory - Kapil Sharma

Writing automated tests is more than just a luxury for any agile software development team. It is a need, and is an essential tool to find bugs quickly during early phases of software development cycles. When there is a new feature that is still in development phase, developers can run automated tests and see how other parts of the system are affected by those changes.
Through test automation, it is possible to lower the cost of bug fixing and bring overall improvement to quality assurance (QA) process. With proper tests, developers get a chance at finding and resolving bugs even before it gets to QA. Test automation further helps us to automate test cases and features that are constantly regressing. This way QAs have more time in testing other parts of the application. Moreover, this helps in ensuring quality of the product in production releases. As a result, we get products that are effectively more stable, and a QA process that is more efficient.
Selenium simplifies test automation for web applications
Selenium simplifies test automation for web applications
Although writing automated tests may seem like an easy task for developers and engineers, there is still the possibility of ending up with poorly implemented tests, and the high cost of code maintenance in any agile process. Trying to constantly deliver changes or features in any agile development project can prove to be costly when tests are involved. Changing one element on a web page that 20 tests rely on will require one to go through these 20 test routines and update each one to adapt to this newly introduced change. Not only can this be really time consuming, but a serious de-motivating factor when it comes to implementing automated tests early on.
But, what if we could make the change in one place only, and have every relevant test routine use it? In this article, we will take a look at automated tests in Selenium, and how we can use Page Object models to write maintainable and reusable test routines.

Page Object Model in Selenium

Page Object model is an object design pattern in Selenium, where web pages are represented as classes, and the various elements on the page are defined as variables on the class. All possible user interactions can then be implemented as methods on the class:
clickLoginButton();
setCredentials(user_name,user_password);
Since well-named methods in classes are easy to read, this works as an elegant way to implement test routines that are both readable and easier to maintain or update in the future. For example:
In order to support Page Object model, we use Page Factory. Page Factory is an extension to Page Object and can be used in various ways. In this case we will use Page Factory to initialize web elements that are defined in web page classes or Page Objects.
Web page classes or Page Objects containing web elements need to be initialized using Page Factory before the web element variables can be used. This can be done simply through the use of initElements function on PageFactory:
LoginPage page = new LoginPage(driver);
PageFactory.initElements(driver, page);
Or, even simpler:
LoginPage page = PageFactory.intElements(driver,LoginPage.class)
Or, inside the web page class constructor:
public LoginPage(WebDriver driver) {           
         this.driver = driver; 
         PageFactory.initElements(driver, this);
}
Page Factory will initialize every WebElement variable with a reference to a corresponding element on the actual web page based on configured “locators”. This is done through the use of @FindBy annotations. With this annotation, we can define a strategy for looking up the element, along with the necessary information for identifying it:
@FindBy(how=How.NAME, using="username")
private WebElement user_name;
Every time a method is called on this WebElement variable, the driver will first find it on the current page and then simulate the interaction. In case we are working with a simple page, we know that we will find the element on the page every time we look for it, and we also know that we will eventually navigate away from this page and not return to it, we can cache the looked up field by using another simple annotation:
@FindBy(how=How.NAME, using="username")
@CacheLookup
private WebElement user_name;
This entire definition of the WebElement variable can be replaced with its much more concise form:
@FindBy(name="username")
private WebElement user_name;
The @FindBy annotation supports a handful of other strategies that make things a bit easier:
id, name, className, css, tagName, linkText, partialLinkText, xpath
@FindBy(id="username")
private WebElement user_name;


@FindBy(name="passsword")
private WebElement user_password;


@FindBy(className="h3")
 private WebElement label;


@FindBy(css=”#content”)
private WebElement text;
Once initialized, these WebElement variables can then be used to interact with the corresponding elements on the page. The following code will, for example:
user_password.sendKeys(password);
… send the given sequence of keystrokes to the password field on the page, and it is equivalent to:
driver.findElement(By.name(“user_password”)).sendKeys(password);
Moving on, you will often come across situations where you need to find a list of elements on a page, and that is when @FindBys comes in handy:
@FindBys(@FindBy(css=”div[class=’yt-lockup-tile yt-lockup-video’]”)))
private List<WebElement> videoElements;
The above code will find all the div elements having two class names “yt-lockup-tile” and “yt-lockup-video”. We can simplify this even more by replacing it with the following:
@FindBy(how=How.CSS,using="div[class=’yt-lockup-tile yt-lockup-video’]")
private List<WebElement> videoElements;
Additionally, you can use @FindAll with multiple @FindBy annotations to look for elements that match any of the given locators:
@FindAll({@FindBy(how=How.ID, using=”username”),
 @FindBy(className=”username-field”)})
private WebElement user_name;
Now that we can represent web pages as Java classes and use Page Factory to initialize WebElementvariables easily, it is time we see how we can write simple Selenium tests using PO and PF patterns.

Simple Test Automation Project in Java

For our simple project let’s automate developer sign up for Toptal. To do that, we need to automate the following steps:
  • Visit www.toptal.com
  • Click on the “Apply As A Developer” button
  • On Portal Page first check if it’s opened
  • Click on the “Join Toptal” button
  • Fill out the form
  • Submit the form by clicking on “Join Toptal” button

Setting Up a Project

  • Download and install Java JDK
  • Download and install InteliJ Idea
  • Create a new Maven project
  • Link “Project SDK” to your JDK, e.g.: on Windows “C:\Program Files\Java\jdkxxx”
  • Setup groupId and artifactId:
<groupId>SeleniumTEST</groupId>
<artifactId>Test</artifactId>
  • Add dependencies Selenium and JUnit Maven in your project POM file
   <dependencies>
        <!-- JUnit -->         
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Selenium -->

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>${selenium.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>${selenium.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>

    </dependencies>
Replace Selenium version and JUnit Version with latest version numbers that can be found by searching for JUnit Maven on Google and on Selenium site.
At this point, if auto build is enabled, dependencies should start downloading automatically. If not, just activate Plugins > install > install:install under the Maven Projects panel on the right side of your IntelliJ Idea IDE.
Once the project has been bootstrapped, we can start creating our test package under “src/test/java”. Name the package “com.toptal”, and create two more packages under it: “com.toptal.webpages” and “com.toptal.tests”.
We will keep our Page Object/Page Factory classes under “com.toptal.webpages” and the test routines under “com.toptal.tests”.
Now, we can start creating our Page Object classes.

HomePage Page Object

The very first one we need to implement is for Toptal’s homepage (www.toptal.com). Create a class under “com.toptal.webpages” and name it “HomePage”.
package com.toptal.webpages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;

public class HomePage {
   private WebDriver driver;

   //Page URL
   private static String PAGE_URL="http://www.toptal.com";

   //Locators

   //Apply as Developer Button
   @FindBy(how = How.LINK_TEXT, using = "APPLY AS A DEVELOPER")
   private WebElement developerApplyButton;

   //Constructor
   public HomePage(WebDriver driver){
       this.driver=driver;
       driver.get(PAGE_URL);
       //Initialise Elements
       PageFactory.initElements(driver, this);
   }

   public void clickOnDeveloperApplyButton(){

       developerApplyButton.click();

   }
}

Determining Element Locators

On Toptal’s homepage we are interested about one element in particular, and that is the “Apply as a Developer” button. We can find this element by matching the text, which is what we are doing above. While modeling web pages as Page Object classes, finding and identifying elements can often become a chore. With Google Chrome or Firefox’s debugging tools, this can be made easier. By right clicking on any element on a page, you can activate the “Inspect Element” option from the context menu to find out detailed information about the element.
One common (and my preferred) way is to find elements using Firefox’s FireBug extension, in combination with Firefox web driver in Selenium. After installing and enabling FireBug extension, you can right click on the page and select “Inspect element with FireBug” to open FireBug. From the HTML tab of FireBug, you can copy the XPath, CSS Path, Tag name or “Id” (if available) of any element on the page.
By copying the XPath of the element in the screenshot above, we can create a WebElement field for it in our Page Object as follows:
@FindBy(xpath = "/html/body/div[1]/div/div/header/div/h1")
WebElement heading;
Or to keep things simple, we can use the tag name “h1” here, as long as it uniquely identifies the element we are interested in:
@FindBy(tagName = "h1")
WebElement heading;

DeveloperPortalPage Page Object

Next, we need a Page Object that represents the developer portal page, one that we can reach by clicking on the “Apply As A Developer” button.
On this page, we have two elements of interest. To determine if the page has loaded, we want to verify the existence of the heading. And we also want a WebElement field for the “Join Toptal” button.
package com.toptal.webpages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class DeveloperPortalPage {
   private WebDriver driver;

   @FindBy(xpath = "/html/body/div[1]/div/div/header/div/h1")
   private WebElement heading;

   @FindBy(linkText = "JOIN TOPTAL")
   private WebElement joinToptalButton;

   //Constructor
   public DeveloperPortalPage (WebDriver driver){
       this.driver=driver;

       //Initialise Elements
       PageFactory.initElements(driver, this);
   }

   //We will use this boolean for assertion. To check if page is opened
   public boolean isPageOpened(){
       return heading.getText().toString().contains("Developer portal");
   }

   public void clikOnJoin(){
       joinToptalButton.click();
   }
}

DeveloperApplyPage Page Object

And finally, for our third and last page object for this project, we define one that represents the page containing developer application form. Since we have to deal with a number of form fields here, we define one WebElement variable for every form field. We find each field by their “id” and we define special setter methods for every field that simulate keystrokes for the corresponding fields.
package com.toptal.webpages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class DeveloperApplyPage {
   private WebDriver driver;

   @FindBy(tagName = "h1")
   WebElement heading;

   @FindBy(id="developer_email")
   WebElement developer_email;

   @FindBy(id = "developer_password")
   WebElement developer_password;

   @FindBy(id = "developer_password_confirmation")
   WebElement developer_password_confirmation;

   @FindBy(id = "developer_full_name")
   WebElement developer_full_name;

   @FindBy(id = "developer_skype")
   WebElement developer_skype;

   @FindBy(id ="save_new_developer")
   WebElement join_toptal_button;


   //Constructor
   public DeveloperApplyPage(WebDriver driver){
       this.driver=driver;

       //Initialise Elements
       PageFactory.initElements(driver, this);
   }

   public void setDeveloper_email(String email){
       developer_email.clear();
       developer_email.sendKeys(email);
   }

   public void setDeveloper_password(String password){
       developer_password.clear();
       developer_password.sendKeys(password);
   }

public void  setDeveloper_password_confirmation(String password_confirmation){
       developer_password_confirmation.clear();
       developer_password_confirmation.sendKeys(password_confirmation);
   }

   public void setDeveloper_full_name (String fullname){
       developer_full_name.clear();
       developer_full_name.sendKeys(fullname);
   }

   public void setDeveloper_skype (String skype){
       developer_skype.clear();
       developer_skype.sendKeys(skype);
   }

   public void clickOnJoin(){
       join_toptal_button.click();
   }
   public boolean isPageOpened(){
       //Assertion
       return heading.getText().toString().contains("Apply to join our network as a developer");
   }
}

Writing a Simple Test

With Page Object classes representing our pages, and user interactions as their methods, we can now write our simple test routine as a series of simple method calls and assertions.
package com.toptal.tests;

import com.toptal.webpages.DeveloperApplyPage;
import com.toptal.webpages.DeveloperPortalPage;
import com.toptal.webpages.HomePage;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.net.URL;
import java.util.concurrent.TimeUnit;

public class ApplyAsDeveloperTest {
   WebDriver driver;

   @Before
   public void setup(){
       //use FF Driver
       driver = new FirefoxDriver();
       driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
   }

   @Test
   public void applyAsDeveloper() {
       //Create object of HomePage Class
       HomePage home = new HomePage(driver);
       home.clickOnDeveloperApplyButton();

       //Create object of DeveloperPortalPage
       DeveloperPortalPage devportal= new DeveloperPortalPage(driver);

       //Check if page is opened
       Assert.assertTrue(devportal.isPageOpened());

       //Click on Join Toptal
       devportal.clikOnJoin();

       //Create object of DeveloperApplyPage
       DeveloperApplyPage applyPage =new DeveloperApplyPage(driver);

       //Check if page is opened
       Assert.assertTrue(applyPage.isPageOpened());

       //Fill up data
       applyPage.setDeveloper_email("dejan@toptal.com");
       applyPage.setDeveloper_full_name("Dejan Zivanovic Automated Test");
       applyPage.setDeveloper_password("password123");
       applyPage.setDeveloper_password_confirmation("password123");
       applyPage.setDeveloper_skype("automated_test_skype");

       //Click on join
       //applyPage.clickOnJoin(); 
   }

    @After
    public void close(){
          driver.close();
       }
   }

Running the Test

At this point, your project structure should look like this:
If you want to run the test, select “ApplyAsDeveloperTest” from the tree, right click on it and then select Run ‘ApplyAsDeveloperTest’.
Once the test has been run, you can see the results in the lower-left corner of your IDE:

Conclusion

Page Object and Page Factory make it easy to model web pages in Selenium and test them automatically and make the life of both developers and QAs much more simpler. When done right, these Page Object classes can be reused across your entire test suite and to give yourself the opportunity to implement automated Selenium tests for your projects early on, without compromising agile development. By abstracting away user interactions in your page object models and keeping your test routines light and simple, you can adapt your test suite to changing requirements with little effort.
I hope I have managed to show you how to write nice and clean test code that is easy to maintain. I will end the article with my favorite QA quote:
Think twice, code once!
This post originally appeared on the Toptal Engineering blog.  

Wednesday, February 10, 2016

Guide to Multi-processing Network Server Models - Kapil Sharma

As someone who’s been writing high performance networking code for a number of years now (my doctoral dissertation was on the topic of a Cache Server for Distributed Applications Adapted to Multicore Systems), I see many tutorials on the subject that completely miss or omit any discussion of the fundamentals of network server models. This article is therefore intended as a hopefully useful overview and comparison of network server models, with the goal being to take some of the mystery out of writing high performance networking code.
Which Network Server Model Should I Choose
This article is intended for “system programmers”, i.e., back-end developers who will work with the low-level details of their applications, implementing network server code. This will usually be done in C++ or C, though nowadays most modern languages and frameworks offer decent low-level functionality, with various levels of efficiency.
I’ll take as common knowledge that since it’s easier to scale CPUs by adding cores, it’s only natural to adapt the software to use these cores as best it can. Thus, the question becomes how to partition software among threads (or processes) which can be executed in parallel on multiple CPUs.
I’ll also take for granted that the reader is aware that “concurrency” basically means “multitasking”, i.e. several instances of code (whether the same code or different, it doesn’t matter), which are active at the same time. Concurrency can be achieved on a single CPU, and prior to the modern era, usually was. Specifically, concurrency may be achieved by quickly switching between multiple processes or threads on a single CPU. This is how old, single-CPU systems managed to run many applications at the same time, in a way that the user would perceive as applications being executed simultaneously, although they really weren’t. Parallelism, on the other hand, means specifically that code is being executed at the same time, literally, by multiple CPUs or CPU cores.
Partitioning an Application (into multiple processes or threads)
Common Network Application Tasks and Network Server Models
  • Task #1: Establishing (and tearing down) of network connections
  • Task #2: Network communication (IO)
  • Task #3: Useful work; i.e., the payload or the reason why the application exists
  • MP: Multi-Process
  • SPED: Single Process, Event-Driven
  • SEDA: Staged Event-Driven Architecture
  • AMPED: Asymmetric Multi-Process Event-Driven
  • SYMPED: SYmmetric Multi-Process Event-Driven
The Multi-Process (MP) Model
The Single Process Event-Driven (SPED) Model
  • Ask the operating system if there are any new network “events” (such as new connections or incoming data)
  • If there are new connections available, establish them (Task #1)
  • If there is data available, read it (Task #2) and act upon it (Task #3)
  • Repeat until the server exits
  1. Since all three tasks are done sequentially in a single loop iteration, the payload work (Task #3) is done synchronously with everything else, meaning that if it takes a long time to compute a response to the data received by the client, everything else stops while this is being done, introducing potentially huge fluctuations in latency.
  1. Only a single CPU core is used. This has the benefit, again, of absolutely limiting the number of context switches required from the operating system, which increases overall performance, but has the significant downside that any other available CPU cores are doing nothing at all.

For the purpose of this discussion, it’s largely not relevant if we are talking about threads or full processes. Modern operating systems (with the notable exception of Windows) treat processes almost as lightweight as threads (or in some cases, vice versa, threads have gained features which make them as weighty as processes). Nowadays, the major difference between processes and threads is in the capabilities of cross-process or cross-thread communication and data sharing. Where the distinction between processes and threads is important, I will make an appropriate note, otherwise, it’s safe to consider the words “thread” and “process” in this section to be interchangeable.
This article deals specifically with network server code, which necessarily implements the following three tasks:
There are several general network server models for partitioning these tasks across processes; namely:
These are the network server model names used in the academic community, and I remember finding “in the wild” synonyms for at least some of them. (The names themselves are, of course, less important – the real value is in how to reason about what’s going on in the code.)
Each of these network server models is further described in the sections that follow.
The MP network server model is the one that everyone used to learn first, especially, when learning about multithreading. In the MP model, there is a “master” process which accepts connections (Task #1). Once a connection is established, the master process creates a new process and passes the connection socket to it, so there is one process per connection. This new process then usually works with the connection in a simple, sequential, lock-step way: it reads something from it (Task #2), then does some computation (Task #3), then writes something to it (Task #2 again).
The MP model is very simple to implement, and actually works extremely well as long as the total number of processes remains fairly low. How low? The answer really depends on what Tasks #2 and #3 entail. As a rule of thumb, let’s say the number of processes or threads should not exceed about twice the number of CPU cores. Once there are too many processes active at the same time, the operating system tends to spend way too much time thrashing (i.e., juggling the processes or threads around on the available CPU cores) and such applications generally end up spending almost all of their CPU time in “sys” (or kernel) code, doing little actually useful work.
Pros: Very simple to implement, works very well as long as the number of connections is small.
Cons: Tends to overburden the operating system if the number of processes grows too large, and may have latency jitter as network IO waits until the payload (computation) phase is over.
The SPED network server model was made famous by some relatively recent high-profile network server applications, such as Nginx. Basically, it does all three tasks in the same process, multiplexing between them. To be efficient, it requires some fairly advanced kernel functionality like epoll and kqueue. In this model, the code is driven by incoming connections and data “events”, and implements an “event loop” which looks like this:
All of this is done in a single process, and it can be done extremely efficiently because it completely avoids context-switching between processes, which usually kills the performance in the MP model. The only context switches here come from system calls, and those are minimized by only acting on the specific connections which have some events attached to them. This model can handle tens of thousands of connections concurrently, as long as the payload work (Task #3) isn’t overly complicated or resource intensive.
There are two major downsides, though, of this approach:
It is for these reasons that more advanced models are required.
Pros: Can be highly performant and easy on the operating system (i.e., requires minimal OS intervention). Only requires a single CPU core.
Cons: Only utilizes a single CPU (regardless of the number that are available). If the payload work is not uniform, results in non-uniform latency of responses.

The Staged Event-Driven Architecture (SEDA) Model

The SEDA network server model is a bit intricate. It decomposes a complex, event-driven application into a set of stages connected by queues. If not implemented carefully, though, its performance can suffer from the same issue as the MP case. It works like this:
  • The payload work (Task #3) is divided into as many stages, or modules, as possible. Each module implements a single specific function (think “microservices” or “microkernels”) which resides in its own separate process, and these modules communicate with one another via message queues. This architecture can be represented as a graph of nodes, where every node is a process, and the edges are message queues.
  • A single process performs Task #1 (usually following the SPED model), which offloads new connections to specific entry point nodes. Those nodes can be either pure network nodes (Task #2) which pass the data to other nodes for computation, or can implement the payload processing (Task #3) as well. There is usually no “master” process (e.g., one that collects and aggregates responses and sends them back over the connection) since every node can respond by itself.
In theory, this model can be arbitrarily complex, with the node graph possibly having loops, connections to other similar applications, or where the nodes are actually executing on remote systems. In practice, though, even with well-defined messages and efficient queues, it can become unwieldy to think, and reason about the system’s behavior as a whole. The message passing overhead can destroy the performance of this model, compared to the SPED model, if the work being done at each node is short. The efficiency of this model is significantly lower than that of the SPED model, and so it’s usually employed in situations where the payload work is complex and time-consuming.
Pros: The ultimate software architect’s dream: everything is segregated into neat independent modules.
Cons: Complexity can explode just from the number of the modules, and message queuing is still much slower than direct memory sharing.

The Asymmetric Multi-Process Event-Driven (AMPED) Model

The AMPED network server is a tamer, easier-to-model version of SEDA. There are not as many different modules and processes, and not as many message queues. Here’s how it works:
  • Implement Tasks #1 and #2 in a single “master” process, in the SPED style. This is the only process doing network IO.
  • Implement Task #3 in a separate “worker” process (possibly started in multiple instances), connected to the master process with a queue (one queue per process).
  • When data is received in the “master” process, find a under-utilized (or idle) worker process and pass the data to its message queue. The master process is messaged by the process when a response is ready, at which point it passes the response through to the connection.
The important thing here is that the payload work is performed in a fixed (usually configurable) number of processes, which is independent of the number of connections. The benefits here are that the payload can be arbitrarily complex, and it won’t affect network IO (which is good for latency). There’s also a possibility for increased security, since only a single process is doing network IO.
Pros: Very clean separation of network IO and payload work.
Cons: Utilizes a message queue for passing data back and forth between processes, which, depending on the nature of the protocol, may become a bottleneck.

The SYmmetric Multi-Process Event-Driven (SYMPED) Model

The SYMPED network server model is in many respects the “holy grail” of network server models, because it’s like having multiple instances of independent SPED “worker” processes. It is implemented by having a single process accepting connections in a loop, then passing them on to the worker processes, each of which has a SPED-like event-loop. This has some very favorable consequences:
  • CPUs are loaded for exactly the number of processes spawned, which at every point in time are either doing network IO or payload processing. There is no way to escalate CPU utilization further.
  • If the connections are independent (such as with HTTP), there is no interprocess communication between the worker processes.
This is, in fact, what newer versions of Nginx do; they spawn a small number of worker processes, each of which runs an event loop. To make things even better, most operating systems provide a function by which multiple processes can listen for incoming connections on a TCP port independently, eliminating the need for a specific process dedicated to working with network connections. If the application you are working on can be implemented in this way, I recommend doing so.
Pros: Strict upper CPU usage ceiling, with a controllable number of SPED-like loops.
Cons: Since each of the processes has a SPED-like loop, if the payload work is non-uniform, latency can again vary, just like with the normal SPED model.

Some Low-level Tricks

In addition to selecting the best architectural model for your application, there are some low-level tricks that can be used to further increase network code performance. Here’s a brief list of some of the more effective ones:
  1. Avoid dynamic memory allocation. As an explanation, simply look at the code for the popular memory allocators – they use complex data structures, mutexes, and there’s simply so much code in them (jemalloc, for example is around 450 KiB of C code!). Most of the models above can be implemented with completely static (or pre-allocated) network and/or buffers that only change ownership between threads where needed.
  2. Use the maximum that the OS can provide. Most operating systems allow multiple processes to listen on a single socket, and implement features where a connection will not be accepted until the first byte (or even a first full request!) is received on the socket. Use sendfile() if you can.
  3. Understand the network protocol you are using! For example, it usually makes sense to disable Nagle’s algorithm, and it can make sense to disable lingering if the (re)connection rate is high. Learn about TCP congestion control algorithms and see if it makes sense to try one of the newer ones.
I may talk more about these, as well as additional techniques and tricks to employ, in a future blog post. But for now, this hopefully provides a useful and informative foundation regarding the architectural choices for writing high performance networking code, and their relative advantages and disadvantages.
This post originally appeared on the Toptal Engineering blog. 

Navigating Portfolio Management Services (PMS): Evaluation, Strategy, and Return Dynamics.

  What is Portfolio Management Services (PMS)? Portfolio Management Services (PMS) are customized, professional investment solutions designe...