分类
如何选择最佳的外汇经纪商

FinRL 入门指南

Adventure

A simple multiplayer text adventure game inspired by old-fashioned, text-based adventure games.

Instructions:

  1. Build Adventure.sln
  2. Start your local Silo from a command window using command file #1.
  3. The game map initialization script, #2
  4. Start the client #3
  5. Reminisce about the good old days before graphical user interfaces

Overview

The AdventureSetup program reads a game description (“map”) from AdventureConfig.txt.

It sets up a series of “rooms” e.g. forest, beach, caves, a clearing etc . These locations are connected to other rooms to model the places and layout of the game. The sample configuration describes only a handful of locations.

Rooms can contain “things” such as keys, swords etc.

The AdventureClient program sets up your player and provides a simple text based user interface to allow you to play the game.

You can move around rooms and interact with things using a simple command language, saying things such as “go north” or “take brass key”.

Why Orleans?

Orleans allows the game to be described via very simple C# code while allowing it to scale to a massive multiplayer game. For this motivation to be meaningful, the labyrinth of rooms needs to be very large and need to support a large number of simultaneous players. One value of Orleans is that the service can be designed for growth, the overhead of running it at a small scale is not significant, and you can remain confident that it will scale if the FinRL 入门指南 FinRL 入门指南 need arises.

How is it modeled?

Player and Rooms are modeled as grains. These grains allow us to distribute the game with each grain modelling state and functionality.

Things such as keys are modeled as plain old objects - they are really just simple immutable data structures that move around rooms FinRL 入门指南 and among players; they don’t need to be grains.

Things for you to do if you are so inclined

  1. Make the map much, much, bigger
  2. Make the brass key unlock something
  3. Allow players to message each other
  4. Make eating food and drinking water possible and meaningful

© 2016 Microsoft Research with help from Jekyll Bootstrap and Twitter Bootstrap

Azure Web Sample

Important note: Worker and web role instances are not automatically removed or disabled, even when they go unused for a long time. To avoid a nasty surprise when your Azure bill comes, make sure to delete the instances after you have finished testing the application!FinRL 入门指南

This sample is almost the same as the Hello World sample, except that it hosts the grains in an Azure Worker Role instead of in the client process itself.

While the communication interface and grain implementation are identical, three projects replace the client:

  • OrleansAzureSample, which is the Azure configuration project.
  • OrleansAzureSilos, the Worker Role integration logic that hosts the Orleans silo in the cloud.
  • WebRole, which provides a simple HTML UI for the Orleans backend.

Run AzureWebSample Locally

The sample is configured to run inside of the Azure Compute Emulator on your desktop by default, so make sure that OrleansAzureSample is set as the Startup Project in this solution and just press F5 to build and run the sample locally.

You do not need to start Visual Studio with administrative privileges to run this sample in the emulator - it is designed to use both IIS Express and Express Emulator, so make sure these options are selected in OrleansAzureSample->Properties->Web. You may also need to select the “Use IIS Express for web sites and projects” in Tools->Options->Projects and Solutions->Web Projects.

Run AzureWebSample in Azure Cloud

To get the sample running in the Azure cloud, open the ServiceConfiguration.Cloud.cscfg file in the OrleansAzureSample project.

Edit the connection strings, replacing MYACCOUNTNAME and MYACCOUNTKEY with data you get from the Azure portal, logged in to your account. It may be useful to set up a new storage account within your subscription just for samples testing. All four connection strings will look exactly the same.

In the file ServiceDefinition.csdef , the configuration sets up all instances as ExtraSmall to avoid any unpleasant surprises. If you want something else, modify the settings as you see fit.

Then, build the solution with Visual Studio and right-click on the OrleansAzureSample project, selecting ‘Publish.’ Visual Studio will take you through the process of publishing your project to Azure, which will take a few minutes.

If things work out, you should see something like this:

This means that the site and its backend are ready. Start a web browser and navigate to the link that VS displayed (or just click on it). You will be greeted by this screen:

Click on “Ask Orleans it’s details” and wait for the response. The first time you interact with the site, it may take a few seconds, since the whole system need to warm up. After that first message, it should go quickly.

© 2016 Microsoft Research with help from Jekyll Bootstrap and Twitter Bootstrap

GPS Tracker

A sample application to show how Orleans could be used in conjunction with SignalR to monitor the position of a number of GPS enabled devices, and report these to a web browser.

In order to run this sample, you need a Bing Maps API key. The key is used by the GPSTracker.Web project, in Views\Home\Index.cshtml.

Running the Sample

Running the sample locally:

  1. Open the FinRL 入门指南 GPSTracker.sln file in Visual Studio 2013, and build the solution.
  2. Start the local Orleans Silo by running the Host project of the solution.
  3. In Visual Studio, right click on the GPSTracker.Web project, and click Set as StartUp Project .
  4. Press F5 to start GPSTracker.Web web application.
  5. Your browser should open on a map of San Francisco.
  6. In a command window, navigate to the GPSTracker.FakeDeviceGateway\bin\Debug directory, and run the ‘GPSTracker.FakeDeviceGateway.exe’ program.
  7. Pushpins should appear on the map, and move around. Blue ones are moving slow, orange faster.

How it Works

The GPSTracker.FakeDeviceGateway.exe program simulates data generated from 20 GPS devices. It randomly alters their speed and heading to simulate the devices moving within rectangular boundaries. It sends the position data to Orleans once a second.

In Orleans, each device is represented by a Device grain. The grain records the previous position of the device, and can therefore calculate the speed of the device. If the devices has moved, the ‘Device’ grain forwards position and speed to a PushNotification grain.

This ‘PushNotification’ grain maintains a C# SignalR client, which connects to a SignalR hub hosted in the GPSTracker.Web project. This allows the grain to ‘push’ messages to the hub without the need for polling the Orleans API. The grain will batch messages together to improve network performance.

The GPSTracker.Web application forwards all messages to connected web browsers using SignalR.

JavaScript running in the browser positions the pins using a Bing Maps control. If the pin has a FinRL 入门指南 low velocity it colors it blue, otherwise orange.

Advantages of using Orleans

This sample is designed to show Orleans as a low-latency messaging system. Orleans is able to hold state for each device in memory (of which there may be many), allowing a quick calculation to be performed (calculating velocity) based on FinRL 入门指南 previous state.

The grain in Orleans can also decide whether the message is worthy of forwarding downstream (has the device moved?) and can therefore filter out unnecessary messages and reduce noise.

The sample also illustrates how SignalR may be used from inside a grain to allow ‘push’ messaging directly to clients.

In a real life scenario you would probably not forward all messages to the browser, and would filter based on groups or device type.

© 2016 Microsoft Research with help from Jekyll Bootstrap and Twitter Bootstrap

Runtime Monitoring

There are five ways Orleans deployment can be monitored by an external operator by utilizing the FinRL 入门指南 data that Orleans writes automatically to Azure storage.

The tables mentioned below are desribed in more detail here.

OrleansSilosTable for cluster membership - this table lists all silos in the deployment (partition key DeploymentID, row key silo id). The operator can use this table to check cluster health, watch the current set of live silos, or learn why and when a certain silo went down. Orleans’ cluster membership protocol uses this table internally and updates it with significant membership events (silos goes up and down).

OrleansSiloMetrics table for coarse grain performance statistics - Orleans writes a small number (about 10) of coarse-grain performance stats into this table (partition key DeplomentID, row key silo id). The table is updated automatically every FinRL 入门指南 FinRL 入门指南 X seconds (configurable) for each silo. The metrics include silo CPU, memory usage, number of grain activations on FinRL 入门指南 this silo, number of messages in the send/receive queue, etc. This data can be used to compare silos, check that there are no significant outliers (for example, one silo runs at much higher CPU), FinRL 入门指南 or simply check that in general the metrics reported by silos are in the expected range. In FinRL 入门指南 addition, this data can be used to decide to add new silos if the system becomes overloaded or reduce the number of silos if the system is mostly idle.

OrleansSiloStatistics table - this table includes a much larger number of performance statistics (hundreds of counters) which provide a much more detailed and FinRL 入门指南 in-depth view of the internal silo state. This table is currently not recommended for use by external FinRL 入门指南 operators. It is mainly for Orleans developers to help them troubleshoot complex production problems, if they occur. The Orleans team is building tools to analyze this data automatically and provide compact recommendations to operators based on it. Such tools can also be built by anyone independently.

Watching error codes in MDS - Orleans automatically writes different error messages into logger. This logger can be configured to output its data to various destinations. For example, the Halo team redirects all logs in production to MDS. They have FinRL 入门指南 written custom alerts in MDS to watch for specific error codes and count their occurrences, and alert them FinRL 入门指南 when those reach a certain threshold. The list of important error codes to watch is specified here:

Windows performance counters - The Orleans runtime continually updates a number of them. CounterControl.exe helps register the counters, and needs to run with elevated privileges. Obviously, the performance counters can be monitored using any of the standard monitoring tools.

© 2016 Microsoft Research with help from Jekyll Bootstrap and Twitter Bootstrap