我正在用 Common Lisp 编写 Web 服务器。现在它工作正常但速度很慢。根据分析,瓶颈是 expt-mod
函数,该函数用于通过 RSA 进行 key 交换。
这是细节。我从客户端(浏览器)得到了 c
。 c
是一个 2048 位整数。我从 RSA 私钥文件中得到了 n
和 d
。 n
和 d
也是 2048 位整数。然后计算(expt-mod c d n)
得到TLS连接的pre-master-key。分析显示如下:
(EXPT-MOD C D N) took 542,184 microseconds (0.542184 seconds) to run.
9,941 microseconds (0.009941 seconds, 1.83%) of which was spent in GC.
During that period, and with 4 available CPU cores
1,057,317 microseconds (1.057317 seconds) were spent in user mode
7,123 microseconds (0.007123 seconds) were spent in system mode
3,309,856 bytes of memory allocated.
10 minor page faults, 0 major page faults, 0 swaps.
我认为它非常慢,因为 OpenSSL 只需要 0.002 秒来处理 TLS 握手。我已经尝试了我自己的 expt-mod、cl-utilities:expt-mod
和 ironclad:expt-mod
版本,但没有成功。分析结果显示几乎相同。
那么我哪里出错了呢?谢谢。
最佳答案
我不确定这是否是答案,但我确实通过从 Closure CL 切换到 SBCL 解决了这个问题。
关于performance - 使用 expt-mod 函数的 Lisp 性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24109530/