In HarmonyOS Next development, the configuration of the ohpm-repo private repository directly affects the development efficiency and the stability of the project. Among them, the config.yaml configuration file plays a crucial role. Today, let's conduct an in-depth analysis of this configuration file and share some practical tips for optimizing the performance of the private repository.
Detailed Explanation of the Configuration File config.yaml
Repository Listening Address (listen)
The listen
parameter is used to specify the listening address and port of the ohpm-repo service, and its format is a three-segment form, that is, <proto>://<host>:<port>
. The default value is localhost:8088
, which means it only listens to the local address. If you want other machines to access your private repository through an IP or domain name, you need to modify the host
to the IP of the machine where ohpm-repo is deployed. For example: listen: http://192.168.1.100:8088
.
Here, the proto
supports the http
and https
protocols, and the default is http
when it is missing. From a security perspective, it is recommended to use the https
protocol. If https
is selected, you also need to configure https_key
and https_cert
, which respectively specify the paths of the SSL certificate private key file and the certificate file. For example:
https_key:./ssl/server.key
https_cert:./ssl/server.crt
Storage Path (deploy_root)
deploy_root
specifies the deployment directory of ohpm-repo, and this directory is used to store the file data generated during runtime. If this field is empty, on the Windows system, the default path is ~/AppData/Roaming/Huawei/ohpm-repo
; on other operating systems, the default path is ~/ohpm-repo
. If you want to customize the path, you must use an absolute path, and the folder pointed to by this path must exist. At the same time, it cannot be the root directory where the ohpm-repo installation package is unzipped. For example:
deploy_root: /home/user/ohpm-repo-data
Maximum Package Size (max_package_size)
max_package_size
is used to limit the size of the uploaded package, with the unit being MB. The default value is 300MB, and the value range is (0, 300]
. In actual projects, if your project often needs to upload relatively large third-party libraries, you may need to adjust this value according to the actual situation. For example, if there are some large resource libraries in the project, you can appropriately increase this limit:
max_package_size: 500
API Timeout (api_timeout)
api_timeout
defines the timeout period for interface requests and responses, with the unit being seconds. The default value is 60 seconds, and the value range is (0, 3600]
. If your network environment is unstable, or certain operations may take a long time, you can appropriately extend this timeout period to avoid request failures caused by network fluctuations:
api_timeout: 120
Selection and Configuration of Different Storage Methods
fileDB vs MySQL Storage
The db
configuration item is responsible for metadata storage and supports fileDB
local storage and mysql
database storage.
- fileDB Local Storage: This is the default storage method, suitable for small projects or scenarios with low requirements for data storage. The configuration is relatively simple, and you only need to specify the storage path:
db:
type: filedb
config:
path:./db
-
MySQL Storage: When the project scale is large and there are higher requirements for data management and performance, you can choose
mysql
storage. You need to configure the database host address, port, username, password, and database name:
db:
type: mysql
config:
host: "localhost"
port: 3306
username: "tctAdmin"
password: "password"
database: "repo"
When choosing mysql
storage, to avoid potential security risks, it is recommended to use a database account with non-highest privileges for connection.
local storage vs sftp vs custom Storage
The store
configuration item is used for the storage of resources such as third-party libraries and their metadata, and it supports local storage
, sftp
storage, and custom
custom plugin storage.
- local storage Local Storage: The default file storage method, suitable for most scenarios. When configuring, you need to specify the storage root directory path and the download address of the repository content:
store:
type: fs
config:
path:./storage
server: http://localhost:8088
-
sftp Storage: Only when the type of
db
ismysql
canstore
usesftp
storage. This storage method is suitable for scenarios where files need to be stored on a remote server. When configuring, you need to specify multiple parameters, such as the host address, port, username, password, and file path:
store:
type: sftp
config:
location:
- name: test_one_sftp
host: "localhost"
port: 22
read_username: "read"
read_password: "password"
write_username: "write"
write_password: "password"
path: /source22
server: http://localhost:8088
-
custom Storage: When you have special storage requirements, you can choose
custom
custom plugin storage. You need to specify the plugin class name, path, and custom fields:
store:
type: custom
config:
export_name: "MyStorage"
plugin_path: "plugins/storagePlugin/MyStorage"
custom_field: "test"
server: http://localhost:8088
Best Practices: How to Optimize the Performance of the Private Repository
Reasonable Configuration of the Cache
-
uplink Cache:
uplink_cache_path
specifies the remote package cache path, and the default is./uplink
;uplink_cache_time
sets the cache time of the remote package metadata, with the unit being hours, and the default is 168 hours. Reasonably adjusting these two parameters can reduce repeated requests for remote resources. If the remote packages relied on by your project are not updated frequently, you can appropriately extend the cache time:
uplink_cache_path: /data/ohpm-repo/uplink
uplink_cache_time: 336
- Local Cache: ohpm-repo itself will cache dependencies as needed, but you can improve the cache efficiency by optimizing the storage path and the cleaning strategy. For example, set the cache directory on a disk partition with fast read and write speeds.
Adjusting the Concurrent Access Limit
The user_rate_limit
parameter is used to control the user access frequency, with the unit being times per second, and the default value is 100 times per second. If your server has good performance, you can appropriately increase this value to support more concurrent accesses, but be careful not to exceed the server's carrying capacity to avoid performance problems:
user_rate_limit: 200
Log Management
Log configuration can help us discover and solve problems in a timely manner. In config.yaml, you can set the storage levels and paths of different types of logs.
-
Log Level:
loglevel_run
,loglevel_operate
, andloglevel_access
are respectively used to set the storage levels of running logs, operation logs, and access logs, and the default level isinfo
. During the development and debugging stages, you can set the log level todebug
to obtain more detailed log information; in the production environment, to reduce the size of the log files and the impact on performance, you can set the level towarn
orerror
:
loglevel_run: debug
loglevel_operate: debug
loglevel_access: debug
-
Log Path:
logs_path
specifies the log storage path, and the default is./logs
. You can set the log path to a disk partition with sufficient space to avoid insufficient disk space caused by overly large log files:
logs_path: /data/ohpm-repo/logs
By having an in-depth understanding of the config.yaml configuration file, reasonably selecting the storage method, and optimizing the performance of the repository, we can make the ohpm-repo private repository better serve HarmonyOS Next development projects, improving development efficiency and the stability of the projects. I hope these experience sharing can be helpful to everyone. If you encounter any problems during the actual use process, you are welcome to discuss and communicate together.
Top comments (0)