Locust installation and setup

Installation

To install Locust, follow the instructions at Locust Installation

  • Create a directory for the Locust project
  • Create a subdirectory for the source code
  • Create a new Anaconda virtual Python environment. ( At the time of writing Python version 3.10 is the latest. )
    conda create -n locust python=3.10
  • Activate the new virtual environment
    conda activate locust
  • Install Locust
    pip3 install locust
  • Check the success of the installation
    locust -V

Troubleshooting

If the check fails with the error message


ValueError: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 152 from C header, got 40 from PyObject

Make sure you use the Anaconda virtual Python environment to avoid version conflicts between installed Python components.

Create your first test

See https://docs.locust.io/en/stable/quickstart.html for the Quick Start tutorial.

  • Create the test file
    locustfile.py
  • Specify the actions to be taken
import time
from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
  wait_time = between(1, 5)

  @task(3)
  def view_items(self):
    # self.client.get(url + "/")
    self.client.get("/")

  @task
  def hello_world(self):
    # self.client.get(url + "/about")
    self.client.get("/about")


  def on_start(self):
    a = 0 # Just a placeholder, as every def has to have at least one executable instruction
    # No login is necessary for this site
    # self.client.post("/login", json={"username":"foo", "password":"bar"})

Starting Locust

  • Open a terminal in the directory where the locustfile.py is located.
  • Start Locust with
    locust -f locustfile.py
  • Open the web UI at http://localhost:8089/
  • Specify the number of concurrent users and the span rate of the users. Enter the URL of the site to be tested. IMPORTANT: Make sure there is no slash at the end of the URL, otherwise the generated URL will contain double slashes!!!
  • Click the Start swarming button.

Changing the load test script

To make sure, Locust will execute the updated script

  • Stop the Locust process in the terminal with CTRL-C
  • Modify and save the locustfile.py file
  • Start the Locust process with
    locust -f locustfile.py

Returning trains do not follow the station list in Railway Empire 2

When we select stations to define a rail line, only one way travel is defined. The returning train always selects the shortest path. In this example Vienna West is in the station list, the return path is not defined, so the train will return through Vienna Ost, the shorter path.  

To make sure the returning train follows the same route, specify the stations for the returning train too.

Making a profit in Railway Empire 2

To increase profit (or reduce losses) you can make adjustments to your empire.

Keep a train lines profitable

Train completed last tour without freight

If the train frequently leaves a station without freight, set the minimum number of wagons to 4 for that station. The train will wait at the station until at least 4 wagons are loaded. Add a track to the station for the train to wait on, so other trans can also use the station.

If you set the other end of the line with the same restriction, it is possible, that the train will very rarely return to this station.  

  • Click the triangle to select the line
  • Click the Edit Rail Line button
  • Hover above the station and click the Edit Station button
  • Set the preferred track, the minimum number of wagons to 4 and click the check mark.
  • Click the Confirm button

Train has been waiting for a free track for some time now

Assign the lines to the tracks of the station. By default trains select the shortest route using the same track of the station.

  •  Select the station
  • Select the Routes using this station button
  • Select a line
  • Click the Edit Rail Line button
  • Hover above the panel of the station and click the Edit Station button
  • Select a track for the line

Keep the businesses profitable

  • Do not oversize the industry. If the level is too high for the demand, the higher operating costs will reduce or eliminate the profit. Slowly increase the level, because if the utilization falls below 60%, the business starts to lose money. This happens if the inflow of raw materials is not enough, or the business cannot sell the products. Make sure you run enough trains to supply the raw materials and ship the products to cities where there is demand for them. Farms do not lose money if the production is mostly continuous.

Error: MUI: The data grid component requires all rows to have a unique id property

Error: MUI: The data grid component requires all rows to have a unique id property.
Alternatively, you can use the getRowId prop to specify a custom id for each row.
A row was provided without id in the rows prop:

The Material UI Data Grid needs to have a unique ID to identify the rows.

To specify the column with the unique numbers, use the getRowId property. 

      <DataGrid
        rows={rows}
        getRowId={(row) => row.MY_ID_COLUMN}
        columns={columns}
      />

Error: EACCES: permission denied, rename ‘/usr/local/lib/node_modules

When a software update changes folder permissions we can lose access to Node.js module locations.

In case of the error message

Error: EACCES: permission denied, rename ‘/usr/local/lib/node_modules

  • Change the folder permission with
sudo chown -R $USER /usr/local/lib/node_modules

Railway Empire 2 industry needs chart

This chart contains the needs of each industries in Railway Empire 2.

The industry needs of Railway Empire 2

To get the information

When a city opens for a new industry

  • Save the game with the name “INDUSTRY LIST in [name of the city]”. This will allow you temporarily open the saved game and explore the industry needs any time.
  • Click the name of the city
  • Select the Construct City Buildings icon
  • Select the Factories icon
  • Select an industry and check the type and quantity of the required raw materials at the bottom of the panel

Build a high traffic railway station in Railway Empire 2

If only one main line runs through your railway station, but the traffic is very high, build a station with 8 tracks. To allow trains to use any track of the station, we could use 8 track gridirons, but those require long parallel tracks. We can use four 2 track gridirons, and combine the tracks with curved tracks in a much smaller footprint. We will also add an 8 track supply tower to refill trains on all tracks.

To prepare the site for the construction,   

  • Lay down 8 parallel tracks with the length of 5 dots. This will smoothen the terrain for the construction.
  • Place four 2 track gridirons as close to the station as possible
  • Place an 8 track supply tower 3 times the tower length from the gridirons
  • Temporarily place another 8 track gridiron 3 times the tower length from the first supply tower to measure the necessary track length for the maintained trains. Later we will delete this tower.
  • Delete the closest track to the main line
  • Build a curved track to join the third track to the first
  • Set the direction of the new curved track
  • When all curves have been created, demolish the second, temporary supply tower

Data access in Remix React.js web applications

Remix vastly simplifies access to backend processes by auto-generating all API calls between the browser and the web server. We only need to create the “loader()” function to get data from the server and the “action()” function to submit a form.

Reading Environment variable values

For security reasons the Node.js web application environment variables are not available in the browser, as those usually contain sensitive information, like database access credentials.

The “loader()” function can read and expose selected environment variables to the browser via the API.

Make sure you have created the /app/routes/_footer.tsx file to display the name of the environment. See Footer in the previous post.

Add the “loader()” function

  • Add the loader() function to the _index.tsx page to get the value of the “environment” environment variable.
  • We will pass the “environment” variable to the Footer to display the value there.
import { LoaderArgs, json} from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";

export default function Index() {

  // -----------------------------------------
  // Get the data from the server side

  // Use "|| {}" to avoid TypeError: Cannot destructure property 'incidents' of 'useLoaderData(...)' as it is null.
  const { environment} = useLoaderData<typeof loader>() || {} ;
  
  // -----------------------------------------


  return (
    <div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>

      {/* Display the Header component */}
      <Header />

      <div className="pagecontent">
        Hello
      </div>

      {/* Display the Footer component */}
      <Footer environment={environment} />

    </div>
  );
}