Advanced Settings
With Advanced Settings in the Arvancloud CDN, you can manage user traffic and load balancing behavior more precisely. To access these features, select your domain in the Arvancloud CDN panel, open its dashboard, and go to Traffic > Advanced Settings.
Load Balancing Type
In this section, you can specify the algorithm used to select an address from among the addresses of your origin servers.
-
Round Robin Algorithm
This is the simplest and most common load balancing algorithm. User requests are distributed among your origin servers in a simple rotation. For example, imagine you have 6 users (u1, u2, u3, u4, u5, and u6) who want to connect to your application, and you have 3 servers (s1, s2, and s3). u1 connects to s1, u2 to s2, and u3 to s3; then u4 connects to s1, u5 to s2, and u6 to s3. The Round Robin algorithm is suitable for predictable requests and for servers with relatively equal processing power and resources.
However, if one of the servers has more capacity to handle requests than the others, you can use weighting to make full use of that server's power.
-
Client IP Hash Algorithm
Client IP Hash is an algorithm that sends user requests to a specific server based on their IP address.
When a user sends a request, the Load Balancer receives it first. The Load Balancer then passes the user's IP address to a hash function. The properties of this hash function can vary. For example, it might convert the last octet of the IP address to an integer and perform a modulo operation on the number of servers to get the server index. In effect, the hash function determines which server should process the request based on the hash of the user's IP address.
As long as the number of servers stays the same and the IP does not change, all future requests from that IP address are directed to the same server.
This algorithm guarantees session persistence: as long as a user's IP address does not change, they keep connecting to the same server throughout their session. This is useful when it is important to keep a client's session information on a specific server.
Send User Request to the Next Server on Error
When you enable this feature and your subdomain is connected to more than one server, requests that encounter errors such as Connection Refused or Connection Error are automatically sent to the next server, and the origin server's error is not shown to the user.
By clicking Settings, you can specify for which errors (status codes) and which HTTP methods a user's request is sent to the next server in the list of upstream servers.
Note that requests that failed on an upstream server may run into problems when processed on the second server. For example, if the connection drops because of network problems while a query is running and the traffic is sent to the next server, duplicate records may be created in the database.
This feature is available on Growth plans and above.
Stop Sending Traffic to a Faulty Server
When you enable this feature, by default, if a server's errors exceed 5, that server is removed for 15 seconds from the list of servers that receive traffic.
You can change the number of errors and the length of time traffic is not sent to the faulty server in the Settings section.
This feature is available on Growth plans and above.
Keep the Connection to the Origin Server Alive
When you enable this feature, connections established with the origin server are kept open for use in subsequent requests. As a result, fewer connections are created with the origin server.
In HTTP/1.0, a new connection is established and closed for each request-response pair. This greatly increases the load on servers.
In HTTP/1.1, however, Keep-Alive Connection is the default behavior: once the client connects to the server, the same connection is used for subsequent requests. This reduces the cost of creating a new connection for each request-response pair.
Overall, Keep-Alive Connection greatly improves website performance by reducing connection latency and saving CPU usage.
gRPC
gRPC is an open, high-speed communication protocol developed by Google. It is based on HTTP/2 and uses binary protocols to transfer data, which makes it faster and more efficient than HTTP/1. gRPC is designed especially for communication between microservices and distributed applications, and it supports concurrent requests, data compression, and bidirectional streaming.
By enabling gRPC, you can send your gRPC requests and responses through the CDN's distributed network, which reduces latency and increases data transfer speed. This is especially useful for real-time applications that need low latency, such as chat or video services.
gRPC Usage Condition
With gRPC traffic, you cannot choose a different Host Header for each origin in the pools. By default, the system selects the Host Header of the first defined origin and uses it for all origins.
So, if your service needs a distinct Host Header for each origin, this is not supported with gRPC.
Supported Ports and Protocols
gRPC can only be served over TLS ports (such as 443). gRPC is only supported over HTTP/2 and is not available over HTTP/1.1 or on non-TLS ports. If you try to use insecure ports or an invalid protocol, the CDN will not establish the connection.
Detecting gRPC Traffic
The CDN can only detect gRPC traffic based on the Content-Type: application/grpc header.
If your client uses gRPC but the Content-Type header has a value other than application/grpc, your traffic will not be detected as gRPC and may be processed as HTTP traffic.
It is recommended that clients explicitly send this header in all their gRPC requests.
Enabling via API
To configure and manage the advanced load balancing settings of the Arvancloud CDN via API, you can use the following sample request:
curl --location --request PATCH 'https://napi.arvancloud.ir/cdn/4.0/domains/arian.run/load-balancers/settings' \
--header 'authority: napi.arvancloud.ir' \
--header 'accept: application/json, text/plain, */*' \
--header 'authorization: API KEY' \
--header 'Content-Type: text/plain' \
--data '{"method":"cluster_chash","next_upstream_tcp":"on","protocol":"https","keepalive":"on","max_fails":5,"fail_timeout":"10s"}'
-
In this request, the
methodkey is used to manage the load balancing type and acceptscluster-rrfor the Round Robin algorithm andcluster-chashfor the Client IP Hash algorithm. -
To manage the "Send User Request to the Next Server on Error" feature, the
next_upstream_tcpkey accepts two values:onandoff. -
The "Stop Sending Traffic to a Faulty Server" settings are managed with two keys,
max_failsandfail_timeout, which accept a positive integer and a time value in seconds, respectively. -
For "Keep the Connection to the Origin Server Alive", use the
keepalivekey. This parameter accepts two values:onandoff.