-
Notifications
You must be signed in to change notification settings - Fork 189
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
Create open-source-summer-experience-sharing-sofarpc-community-open-s… #1311
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# 开源之夏经验分享|SOFARPC 社区郑佳莉:开源的收获不止代码 | ||
|
||
> **文|郑佳莉** | ||
> | ||
> 计算机学院研二在读 | ||
> SOFARPC 社区贡献者 | ||
> | ||
> 就读于国防科技大学计算机学院研二。专注 Java 领域,探索基础架构与中间件技术中。 | ||
> | ||
> **本文 2476 字,预计阅读 7 分钟** | ||
|
||
今天 SOFAStack 邀请到了开源之夏 2024 SOFARPC 社区的中选学生**郑佳莉**同学!在本项目中,她参与完成了 **SOFARPC 动态配置能力完善**。希望她分享的这段经历,能让更多人了解到 SOFARPC 开源社区,感受开源的魅力~ | ||
|
||
**项目链接**:[*https://summer-ospp.ac.cn/org/prodetail/2495a0307*](*https://summer-ospp.ac.cn/org/prodetail/2495a0307*) | ||
|
||
## 项目信息 | ||
|
||
**项目名称**:SOFARPC 动态配置能力完善 | ||
|
||
**项目导师**:刘建军 | ||
|
||
**项目背景**: | ||
|
||
RPC 动态配置能力是指运行时针对 RPC 相关的配置进行修改,使其能够根据需要动态调整行为,而无需重新启动服务或强制更新客户端应用程序。动态配置能力通常包括动态调整负载均衡策略、重试策略、超时设置、限流和熔断策略、序列化和反序列化配置等。 | ||
当前 SOFARPC 简单集成了 Apollo 配置中心,期望梳理出 SOFARPC 相关需要支持的动态配置,完善对应的接口维度的动态配置能力。另外,在此基础之上,期望在 SOFARPC 中集成 Nacos、Zookeeper 等作为配置中心,支持对应的动态配置能力。 | ||
|
||
## 项目实现思路 | ||
|
||
### 方案描述 | ||
|
||
**SOFARPC 原本的配置情况如下:** | ||
|
||
简单集成了 Apollo 作为配置中心; | ||
仅支持请求维度的动态配置,需要在调用流程中去主动获取对应的配置,支持的配置项包括超时时间和负载均衡策略。 | ||
|
||
针对以上两点,改进方案分为以下三部分: | ||
|
||
**1、进一步集成 Nacos、Zookeeper 作为配置中心,并在此基础上支持请求维度的动态配置** | ||
|
||
各配置中心内,请求维度配置信息的存储结构设计如下图,其中每个配置节点的数据对应着单个配置项的值: | ||
|
||
 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify image availability and consider using relative paths. The article uses absolute URLs for all images, pointing to img.alicdn.com. While these might work currently, using absolute URLs from external domains creates dependencies on external services. If the external service changes its URL structure or becomes unavailable, the images will break. Also applies to: 48-48, 54-54, 60-60, 64-64 🏁 Script executed: #!/bin/bash
# Description: Check if the images referenced in the article are accessible
# Create an array of image URLs
declare -a image_urls=(
"https://img.alicdn.com/imgextra/i1/O1CN01uam04Y1vr6Xyhl4qr_!!6000000006225-0-tps-1080-654.jpg"
"https://img.alicdn.com/imgextra/i3/O1CN01bTopnq1F8U669LruX_!!6000000000442-0-tps-1048-264.jpg"
"https://img.alicdn.com/imgextra/i4/O1CN01ICkkAC1hBVxddRJ89_!!6000000004239-0-tps-1080-617.jpg"
"https://img.alicdn.com/imgextra/i3/O1CN01BfI96r1YNZqmoPYHV_!!6000000003047-0-tps-821-320.jpg"
"https://img.alicdn.com/imgextra/i2/O1CN01kfVMPK20WYrRRGTdr_!!6000000006857-0-tps-760-291.jpg"
)
# Check if each image is accessible
for url in "${image_urls[@]}"; do
response=$(curl -s -o /dev/null -w "%{http_code}" "$url")
if [ "$response" == "200" ]; then
echo "✅ Image accessible: $url"
else
echo "❌ Image not accessible (HTTP $response): $url"
fi
done
# Check if the repository has local images for similar blog posts
echo -e "\nChecking repository for image storage patterns:"
fd -t f -e jpg -e png -e jpeg -e gif -e svg -d 3 . | head -n 5 Length of output: 2901 🌐 Web query:
💡 Result: For Hugo-based static sites, the recommended image storage practices for blog posts emphasize leveraging Hugo's built-in processing capabilities while maintaining organizational efficiency. Here are the key strategies: Page Bundles (Preferred Method)Store images within content directories using Hugo's page bundles:
This approach enables:
Image Optimization Techniques
{{ with .Resources.GetMatch "featured-image.jpg" }}
{{ $webp := .Resize "800x webp" }}
{{ $jpeg := .Resize "800x jpeg" }}
<picture>
<source srcset="{{ $webp.RelPermalink }}" type="image/webp">
<img src="{{ $jpeg.RelPermalink }}"
loading="lazy"
width="{{ $jpeg.Width }}"
height="{{ $jpeg.Height }}"
alt="Post featured image">
</picture>
{{ end }}
Alternative Storage Options
Workflow Recommendations
For most Hugo blogs, page bundles combined with responsive image processing provide the best balance of performance, maintainability, and Hugo integration. This approach reduced one user's image storage by 44% while improving site speed [6]. Citations:
Action: Update image paths to use Hugo page bundles or relative paths The images are currently accessible via absolute URLs from an external host, which works at the moment but introduces a dependency on an external service. To improve long-term maintainability and leverage Hugo’s built-in image processing, consider migrating these images into your content structure (e.g., as page bundles) and referencing them via relative paths. This change will help prevent potential breakage if the external URL structure changes or becomes unavailable.
|
||
|
||
**2、梳理出 SOFARPC 相关需要支持的动态配置选项** | ||
|
||
动态配置选项如下表所示: | ||
|
||
 | ||
|
||
**3、增加接口维度的动态配置能力** | ||
|
||
各配置中心内,接口维度配置信息的存储结构设计如下图,其中,每个配置节点中的数据存储格式为 properties,单个配置节点的数据对应着某个接口的多个配置项: | ||
|
||
 | ||
|
||
动态配置能力通过对配置进行监听来实现,当配置中心中的配置发生变化时,SOFARPC 应自动检测到新的配置并更新到接口配置实例中。 | ||
|
||
添加接口维度配置监听器的流程如下: | ||
|
||
 | ||
|
||
接口维度配置动态更新流程如下: | ||
|
||
 | ||
|
||
## 开源之夏个人随访 | ||
|
||
### 自我介绍 | ||
|
||
大家好,我叫郑佳莉,是国防科技大学计算机学院研二的学生。我日常主要使用 Java 进行开发,对基础架构和中间件技术十分感兴趣。 | ||
|
||
这是我第一次参与开源之夏,通过参与 SOFAStack 社区的项目,我得以深入体验开源社区的工作流程和开发过程。 | ||
|
||
### 申请本社区项目的原因 | ||
|
||
在之前的学习和实践中,我曾参与过一些分布式系统的开发工作,并且,我在学校的分布式计算课程中实现过一个简易的 RPC 框架。通过这些经历,我对 RPC 框架的工作原理和服务治理的挑战有了较为深入的理解。 | ||
|
||
SOFARPC 作为一个广泛使用的开源 RPC 框架,吸引了我参与其中,希望能在项目中进一步扩展我的知识和技能。特别是看到 SOFARPC 在动态配置方面的潜力后,我希望能够贡献自己的力量优化系统,帮助开发者更好地管理配置。 | ||
|
||
### 如何克服项目过程中的困难与挑战? | ||
|
||
在项目过程中,我面临的主要难题是如何在不影响系统现有配置功能的前提下,扩展动态配置功能,尤其是要兼容不同的配置中心。由于不同配置中心的存储结构不同,接口实现和配置更新策略存在较大差异,导致了配置管理类的实现复杂度增加,兼容性问题也相应变得更加突出。 | ||
|
||
针对这些问题,我提出了以下解决方案: | ||
|
||
**统一存储层次和抽象设计**:为了更好地兼容不同的配置中心,我设计了统一的存储层次结构,在每个配置中心内部,接口级的配置信息均与应用名相对应。此外,通过 SPI 机制,使用统一的 DynamicConfigManager 接口,不同配置中心的实现方式被抽象为一个统一的层,减少了各配置管理类之间的耦合。 | ||
|
||
**监听机制的统一和优化**:为了实现动态配置的实时生效,需要对配置变更进行事件监听。然而,由于 Apollo、Nacos 和 Zookeeper 的监听机制不同,初期设计的监听器存在重复创建和事件丢失的问题,导致部分配置更新时没有及时生效。为了解决这一问题,我分别为不同配置中心实现了其特定的 Listener 子类,并在 DynamicConfigManager 中引入了统一的监听器管理机制。通过引入 ConfigChangedEvent 事件类,我成功统一了事件的触发和处理逻辑,解决了事件丢失和重复创建的问题。 | ||
|
||
经过多次实验和调整,并在导师的指导下不断优化,最终我成功实现了负载均衡策略、超时设置等配置项的动态更新,并顺利集成了 Nacos 和 Zookeeper。 | ||
|
||
### 导师与社区带来的帮助 | ||
|
||
在整个项目过程中,我得到了导师和社区的悉心指导与支持。项目启动之初,导师便帮助我梳理了项目的核心需求和整体的任务安排,在之后的每周,我们都会定期召开会议,汇报进度并商讨进一步的实现思路。在整个项目周期内,导师为我提供了诸多宝贵的技术建议。 | ||
|
||
### 社区印象 | ||
|
||
SOFAStack 社区是一个充满创新精神和协作氛围的开源平台,汇聚了许多技术爱好者和开发者。社区成员不仅拥有丰富的技术背景,也热衷于分享和贡献自己的经验与成果。在这里,每个人都能找到志同道合的伙伴,彼此帮助、共同进步。 | ||
|
||
### 有哪些收获 | ||
|
||
我不仅深入理解了 SOFARPC 框架的设计与实现,还学到了如何在大型开源项目中推动功能优化与创新。我学会了如何在扩展功能的同时,平衡系统稳定性与灵活性之间的关系,避免引入不必要的复杂性。这一经验对我未来的技术工作具有深远影响,尤其是在处理复杂系统的设计与优化时,我将更加注重架构的清晰性与可维护性。 | ||
|
||
### 对更多开源新人的寄语 | ||
|
||
开源之路充满挑战,但也极富回报。勇于尝试,保持对技术的热情,你将在这个过程中不断成长! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix link formatting syntax.
The link format has unusual asterisks both inside and outside the brackets and parentheses, which may cause rendering issues. Markdown links should follow the format
[text](url)
without asterisks.📝 Committable suggestion