小编mar*_*ark的帖子

如何从URL中的node.js服务器文件夹中获取图像?

有人知道如何从URL中的node.js服务器文件夹中获取图像吗?在我的文件夹结构中,我有文件夹数据,里面有子文件夹img with image.我想用URL访问此图像,如下所示:

http://localhost:3000/data/img/default.jpg
Run Code Online (Sandbox Code Playgroud)

但当我进入浏览器时,我总是收到此错误:

未找到页面/data/img/default.jpg不是有效路径.

server.js:

'use strict';
/**
 * Module dependencies.
 */
var init = require('./config/init')(),
    config = require('./config/config'),
    mongoose = require('mongoose');
var express = require('express');

/**
 * Main application entry file.
 * Please note that the order of loading is important.
 */

// Bootstrap db connection
var db = mongoose.connect(config.db, function(err) {
    if (err) {
        console.error('\x1b[31m', 'Could not connect to MongoDB!');
        console.log(err);
    }
});

// Init the express application
var app = require('./config/express')(db);

// Bootstrap passport config …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express mean-stack mean.io

9
推荐指数
1
解决办法
2万
查看次数

为什么并行任务在第一时间总是很慢?

我有一些分类器,我想对一个样本进行评估。由于它们彼此独立,因此可以并行运行此任务。这意味着我要并行化它。

我用python和bash脚本尝试过。问题是,当我第一次运行该程序时,大约需要30到40秒才能完成。当我连续多次运行该程序时,只需1s-3s即可完成。即使我用不同的输入来输入分类器,我也得到了不同的结果,因此似乎没有缓存。当我运行其他程序并随后重新运行该程序时,它又需要40秒钟才能完成。

我在htop中还观察到,第一次运行该程序时CPU利用率不高,但是当我一次又一次重新运行时,CPU利用率就很高。

有人可以向我解释这种奇怪的行为吗?我如何避免这种情况,这样即使程序第一次运行也会很快?

这是python代码:

import time
import os
from fastText import load_model
from joblib import delayed, Parallel, cpu_count
import json

os.system("taskset -p 0xff %d" % os.getpid())

def format_duration(start_time, end_time):
    m, s = divmod(end_time - start_time, 60)
    h, m = divmod(m, 60)
    return "%d:%02d:%02d" % (h, m, s)

def classify(x, classifier_name, path):
    f = load_model(path + os.path.sep + classifier_name)    
    labels, probabilities = f.predict(x, 2)
    if labels[0] == '__label__True':
        return classifier_name
    else:
        return None

if __name__ == '__main__':
    with open('classifier_names.json') as …
Run Code Online (Sandbox Code Playgroud)

python parallel-processing bash joblib

5
推荐指数
1
解决办法
211
查看次数