Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the Why Swift on Server section and add page on concurrency. #496

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tachyonics
Copy link

@tachyonics tachyonics commented Jan 25, 2024

Refactor the "Why Server on Swift?" section, adding content on concurrency features and provide room for further expansion.

Motivation:

The "Why Server on Swift?" has not been updated for a significant time and doesn't reflect a lot of features that could be considered advantages for using Swift for server-side applications.

Modifications:

  1. Moved the "Why Server on Swift?" content out of the main server index page.
  2. Create an index page for "Why Server on Swift?" which links to separate pages. This can be expanded with additional pages in the future.
  3. Move the existing "Why Server on Swift?" content to a "Performance" page which can be expanded in the future with actual performance data.
  4. Added a new "Concurrency" page to describe various features that Swift provides.

Result:

The "Why Server on Swift?" section will be expanded into an index page and an additional section on concurrency features.

@0xTim
Copy link
Collaborator

0xTim commented Jan 26, 2024

@swift-ci test

Copy link
Collaborator

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A couple of things that need tweaking I spotted

title: Why Swift on Server - Performance
---

For the same reasons that make Swift is a fantastic choice for embedded and constrained environments such as watches and phones, Swift makes it possible to write simple, elegant server-side applications that are also highly efficient.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph needs reworking. There's a couple of grammar errors and the flow is a little off


## Small footprint
One of the main goals of a modern cloud platform is to maximize resource utilization by efficiently packing services into a single machine.
Cloud services built with Swift have a small memory footprint (measured in MB)--especially when compared to other popular server languages with automatic memory management.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cloud services built with Swift have a small memory footprint (measured in MB)--especially when compared to other popular server languages with automatic memory management.
Cloud services built with Swift have a small memory footprint (measured in MB) - especially when compared to other popular server languages with automatic memory management.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth having something on safety here as well? It might end up being a separate section though


## Deterministic performance
Swift’s use of ARC (instead of tracing garbage collection) and its lack of JIT gives it an important edge in the cloud services space.
While tracing garbage collection technologies have vastly improved in the last few years, they still compete with the application for resources which triggers non-deterministic performance.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
While tracing garbage collection technologies have vastly improved in the last few years, they still compete with the application for resources which triggers non-deterministic performance.
While tracing garbage collection technologies have vastly improved in the last few years, they still compete with the application for resources when triggered which results in non-deterministic performance.


Swift utilizes a built-in "async/await" style syntax that by default hides the complexity of concurrent programming. Similar to how Swift uses the explicit `try` keyword at function call sites to indicate that a function might throw, the `await` keyword is used to indicate that a function may suspend its processing to asynchronously wait on some future event or completion of another task.

~~~ swift
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you verified that ~~~ produce a code block? I thought it was only three backticks that worked

1. [`swift-log`](https://github.com/apple/swift-log)'s Metadata Providers: Swift's unified logging API, swift-log, provides the ability to retrieve log metadata from Task Locals and incorporate them into any logs emitted. In http request/response applications for example, this allows any logs - including those emitted from libraries with no knowledge of how the top-level application works - to include log metadata such as requestIds and other information about the incoming request.
1. [swift-distributed-tracing](https://github.com/apple/swift-distributed-tracing): Swift's unified distributed tracing API allows specific tracing implementations to set tracing context from incoming requests and to then set it on any outgoing requests made in that task or any child task.

For most server-side use cases, the [ServiceContext](https://github.com/apple/swift-service-context) type, modeled after the concepts explained in [W3C Baggage](https://w3c.github.io/baggage/) and built on top of Task Locals, will be a convenient mechanism to transport task-specific information. This type easily allows for custom attributes to be stored and retrieved in a type-safe manner. This type is also the basis for `swift-distributed-tracing`'s trace identifier propagation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modeled

Cries in British English 😆


## Thread Safety

Server-side applications are often highly concurrent, often with many hundreds or even thousands of requests executing in parallel within the same application. In these cases it is critical for correctness - and potentially even availability - that these requests can all run in parallel without unexpectedly affecting each other. Failing to make applications thread safe often results in unpredictable and difficult-to-debug race conditions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra often

Suggested change
Server-side applications are often highly concurrent, often with many hundreds or even thousands of requests executing in parallel within the same application. In these cases it is critical for correctness - and potentially even availability - that these requests can all run in parallel without unexpectedly affecting each other. Failing to make applications thread safe often results in unpredictable and difficult-to-debug race conditions.
Server-side applications are often highly concurrent, with many hundreds or even thousands of requests executing in parallel within the same application. In these cases it is critical for correctness - and potentially even availability - that these requests can all run in parallel without unexpectedly affecting each other. Failing to make applications thread safe often results in unpredictable and difficult-to-debug race conditions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants